SQL Query return data for 5 columns linked to the same Lookup Table

BigH61 581 Reputation points
2023-04-07T18:44:41.6266667+00:00

I have a Main table that is joined to a second Table via the Main tables primaryKey. Within the second table there are multiple columns but 5 of these columns all reference the same lookup table. I have an SQL Query that returns all the relevant records from the Main table and the Second table with the exception of the 5 columns linked to one Lookup table. How can i return this data also. Thank you for your assistance.

SQL Server Other
{count} votes

Accepted answer
  1. LiHongMSFT-4306 31,566 Reputation points
    2023-04-10T02:33:52.6766667+00:00

    Hi @BigH61 Not sure what you actually want, but If I understood right, you need to use Join twice. Try something like this:

    SELECT M.<column list>,S.<column list>,L.<column list>
    FROM MainTable M JOIN SecondTable S ON M.primaryKey=S.ForeignKey
                     JOIN LookUpTable L ON M.primaryKey=L.ForeignKey
    

    Best regards,

    Cosmog Hong


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.