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 996919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:57:04+00:00 2026-05-16T06:57:04+00:00

I have a SQL DB that contains multiple relational tables. There are some fields

  • 0

I have a SQL DB that contains multiple relational tables. There are some fields in the master table that reference another table multiple times. For example, say I have a database of salesmen who are responsible of sales for multiple states. My database has fields for State1, State2, and State3 all of which map back to a States table. I can’t figure out for the life of me how to write a query to return a record with all the enumerated states. If I only needed one State field, I know I would do:

SELECT Master.Name, State.Enumeration AS 'State'
FROM MasterTable Master, StateTable State
WHERE Master.State1 = State.ID;

How can I expand this for all my State fields?

Thanks.

  • 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-05-16T06:57:05+00:00Added an answer on May 16, 2026 at 6:57 am

    Returning a column from each of the unique joins to the states:

    select m.Name, s1.Enumeration as State1, s2.Enumeration as State2, s3.Enumeration as State3
    from MasterTable m
    left join StateTable s1 on m.State1 = s1.ID
    left join StateTable s2 on m.State2 = s2.ID
    left join StateTable s3 on m.State3 = s3.ID
    

    Returning 1 column of all the states from the 3 joins:

    select m.Name, ISNULL(s1.Enumeration + ',','') 
                   + ISNULL(s2.Enumeration + ',','') 
                   + ISNULL(s3.Enumeration,'') as Enumeration
    from MasterTable m
    left join StateTable s1 on m.State1 = s1.ID
    left join StateTable s2 on m.State2 = s2.ID
    left join StateTable s3 on m.State3 = s3.ID
    

    There is also column-queries…

    select m.Name,
     ISNULL((select Enumeration from StateTable where ID = m.State1),'') as State1,
     ISNULL((select Enumeration from StateTable where ID = m.State2),'') as State2,
     ISNULL((select Enumeration from StateTable where ID = m.State3),'') as State3
    from MasterTable m
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table in SQL Server called [Donations] that contains donations given by
I have an SQL Server 2005 table that has a varchar(250) field which contains
I have a table which contains my ads that can be searched in sql-server-2008.
I have a transaction that contains multiple SQL Statements (INSERT, UPDATE and/or DELETES). When
I have two simple tables in my database. A card table that contains Id,
I have a database with 3 tables. The first table contains students with fields
I have a VB.Net data set that contains data from multiple tables. Does anyone
I have an SQL DB that contains Lat and Long info. I have found
I have the Execute SQL Script package that contains the script to insert about
I have a web app that reads data from a SQL DB that contains

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.