Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8831075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:13:56+00:00 2026-06-14T08:13:56+00:00

The following sql query below produced this result cust table CUST_ID AC_NO NAME AREA

  • 0

The following sql query below produced this result

cust table

CUST_ID     AC_NO      NAME            AREA  SALES
---------- ---------- ------------------------- ---
C001       A30045     Smiths Heavy       1   R001
C002       A30145     Heavy jonps        1   R001
C003       A30046     dangote flour      1   R002
C004       A30047     OAU ife            2   R002


Area Table

AREA_NUMBER AREA_NM  AREA_Dp
----------- ---------- ----------
      1 North      Leeds
      2 South      Newcastle
      3 East       Surrey
      4 West       London



Area_geo Table


SALE REPP_   AREAA_ID AREAM AREAMANAGER_NAME
---- ----- ---------- ----- -------------------
SG01 R001           1 R110  mandy Jay
SG02 R002           2 R110  mandy Jay
SG03 R003           3 R111  Kay sole
SG04 R003           3 R111  Kay sole
SG05 R003           3 R111  Kay sole
SG06 R001           4 R110  mandy Jay




  select cust.*,
  area.AREA_Nm,area.AREA_Dp
   from area inner join cust on
   area.area_number=customer.area
   ORDER BY customer.Cust_ID;

Result

 CUST_ID    AC_NO      NAME            ADDRESS         AREA  SALES  AREA_N  AREA_Dp
 ---------- ---------- -------------- ------------------------- ---------- ----- ---
 Ac003       A30046     dangote flour  court Estate     1    R002   North      Leeds
 Ac004       A30047     OAU ife        4 Abanishe       2    R002   South      Newcastle

my intension is to further include the Areamanager_name into the above result from the table below. the table below however has a common attribute (Area_ID) to the above result (Area)

Table Area_Geo

SALE REPP_   AREA_ID  AREAM   AREAMANAGER_NAME
---- ----- ---------- ----- ----------------
SG01 R001        1    R110    mandy Jay
SG02 R002        2    R110    mandy Jay
SG03 R003        3    R111    Kay sole
SG04 R003        3    R111    Kay sole
SG05 R003        3    R111    Kay sole
SG06 R001        4    R110    mandy Jay

expected result

 CUST_ID    AC_NO      NAME            ADDRESS         AREA  SALES  AREA_N   AREA_dp Areamanager
 ---------- ---------- -------------- ------------------------- ---------- ----- ---
 Ac003       A30046     dangote flour  court Estate     1    R002   North    Leeds     mandy Jay
 Ac004       A30047     OAU ife        4 Abanishe       2    R002   South    Newcastle mandy Jay
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:13:57+00:00Added an answer on June 14, 2026 at 8:13 am

    I think the below should do it, I reformatted it a bit so I could read it a bit easier. You
    would need an outer join if sometimes you didn’t have an area manager.

    SELECT cust.*
          ,area.area_Nm
          ,area.AREA_Dp
          ,area_geo.Areamanager_name
    FROM area inner join cust     on area.area_number = customer.area
              inner join area_geo on area.area_number = area_geo.area_id
    ORDER BY customer.Cust_ID;
    

    edit in response to comment :-

    The problem of double values is caused by the fact that the area_geo table can have ( and in the case of area_id 3 appears to have ) duplicate values for an area_id. When you do a join a row is returned for each row in the table, so for area_id 3 rows would be returned every time. You could do use a sub query

    SELECT cust.*
          ,area.area_Nm
          ,area.AREA_Dp
          ,(SELECT DISTINCT area_geo.Areamanager_name
            FROM   area_geo
            where  area.area_number = area_geo.area_id) Areamanager_name
    FROM area inner join cust     on area.area_number = customer.area
    ORDER BY customer.Cust_ID;
    

    But if there are different values of Areamanager_name for the same area_id, this query will fail. Ideally I think you need to use a more suitable table to retrieve the areamanager_name, or if there isn’t one normalize your database so that there is only 1 record in area_geo for each area_id.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This concerns sql show queries. The following query below works the issue is it
The following sql query below produces the specified result. select product.product_no,product_type,salesteam.rep_name,salesteam.SUPERVISOR_NAME from product inner
When the SQL query below is executed: UPDATE shop_category SET name = 'Secolul XVI
I have the following in Confluence: {panel} Hello World 1 {panel} {sql-query:datasource=DS|output=wiki|table=false|macros=true} select '\{panel\}\\'
Given the SQL statements below, I would expect the result of the query to
I have been profiling the SQL query NHibernate generates for the following snippets below.
Does anyone know what is wrong with the following SQL query? CREATE TABLE IF
A sql query returns many rows of the following simple structure: name, id I
I have the following table: I am trying to create an SQL query that
Following my [question]: T-SQL Query a matrix table for free position I've now trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.