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

  • Home
  • SEARCH
  • 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 8890715
In Process

The Archive Base Latest Questions

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

I have three tables: SN | Table Name | Primary Key | Foreign Key

  • 0

I have three tables:

SN | Table Name  | Primary Key   | Foreign Key | Attribute 
-----------------------------------------------------------------
1  | salesArea   | salesAreaID   |             | areaDescription
2  | store       | storeID       | salesAreaID | 
3  | salesPerson | salesPersonID | storeID     | salesPersonName 

I am trying to get the salesPersonName(s) of anyone that is in the same salesArea as a certain salesPerson.

For instance, a salesPerson named David works in storeID 23, which is in the NE salesArea.
There is another salesPerson named Bob working in storeID 34, which is also in the NE salesArea.

My query so far is…

SELECT salesPersonName,
salesPersonID,
    st.salesAreaID,
    areaDescription,
    sp.storeId
  FROM salesperson as sp, salesArea as sa, store as st

I am confused on how to get it get the storeID of ‘David’ and then retrieve what the salesArea is. Then with that salesArea, retrieve all salesPersons with that salesArea.

Salesperson table only gives the storeID, but then store gives the salesArea for the storeIDs.

Point in the right direction would be nice, join clause? some fancy where with a group by?

  • 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-14T22:33:58+00:00Added an answer on June 14, 2026 at 10:33 pm

    I am assuming:

    • Areas have stores
    • stores have salespersons
    • salespersons have names

    So, we first want to find the area ID of the salesperson passed:

    SELECT sp.SalesPersonID, st.SalesAreaID
    FROM salesperson as sp
    INNER JOIN store as st on sp.StoreID = st.StoreID
    WHERE sp.SalesPersonName = 'David'
    

    Now, we could use the results of this query to then execute the second part of the question, which is “get the other people in a given salesarea”. If, for example, the above query returned SalesAreaID = 23 and SalesPersonID = 10, our second query would look like the following:

    SELECT sp.SalesPersonID, sp.SalesPersonName, st.StoreID
    FROM stores st
    INNER JOIN salespersons sp on st.StoreID = sp.StoreID
    WHERE st.SalesAreaID = 23 and sp.SalesPersonID <> 10
    

    But, we can combine the two queries to form a single one that does the same thing:

    SELECT sp2.SalesPersonID, sp2.SalesPersonName, st2.StoreID
    FROM salesperson as sp
    -- Join to stores to get the areaID of the salesperson passed (multiplicity 1)
    INNER JOIN store as st on sp.StoreID = st.StoreID
    -- self join to store to get all stores in that area (multiplicity 1 x Stores[area])
    INNER JOIN store as st2 on st.SalesAreaID = st2.SalesAreaID
    -- get all salespersons assigned to all stores in the area (multiplicity 1 x salespersons[area])
    INNER JOIN salesperson as sp2 
        on st2.StoreID = sp2.StoreID 
        -- only return "other" salespersons
        and sp2.SalesPersonID <> sp.SalesPersonID
    WHERE sp.SalesPersonName = 'David'
    

    Et voilà, we have a query giving all other salespersons in a the same area as a passed salesperson.

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

Sidebar

Related Questions

I have three tables A: A.pID primary key, A.Name nvarchar(250) B: B.pID primary key,
I have three tables: 1. User (id, name, birthdate) - PRIMARY KEY ('id') 2.
I have three tables like this: Person table: person_id | name | dob --------------------------------
I have three tables, Name - columns Custpackingslipjour(table 1) - (deliverydate, dateclosed,, salesid) Inventrans
I have two tables in which the second table has a foreign key which
I have defined three tables, Stores, InventoryItems and StoreItemRecords. My StoreItemRecords table has foreign
I have three tables like this: Table 1 structure: Name: registered_applicant_details Fields: applicant_id INT
Using MySQL, I have three tables: projects : ID name 1 birthday party 2
I have three tables filters (id, name) items(item_id, name) items_filters(item_id, filter_id, value_id) values(id, filter_id,
I have three tables Person (id, name, email) Address (id, Person_id, address, verified) Person_Claimed

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.