Avatar of Jim Sokol
Jim Sokol
Flag for United States of America asked on

How can I join 2 tables in SQL.

I have a relatively simple query, but I cant seem to figure it out. I have two tables that contain some information that I need to retrieve. They are the checked values.

I need to join these two tables and query 

WHERE udm_win_id = @param1 AND udm_app_id = @param2.

Here is the query that I have, but it is not returning all of the data that I need, because in the UDM table I have rows that dont exist in the TemplateValues table.

SELECT UDM.udm_field_id,
FROM UserDataAccessMultiTier UDM
    INNER JOIN TemplateValues TV
        ON TV.td_field_id = UDM.udm_field_id
           AND TV.tv_value_id = UDM.udm_value_id
WHERE UDM.udm_win_id = @win_id
      AND UDM.udm_app_id = @app_id;

The red outlined data is not being returned.

Basically, I need the data form the UDM table and also the corresponding udm_field_id.  Also the udm_value_id is set to * in the TemplateValues  table becuase it can have many different values i.e. testing 1, testing 2 etc...


Avatar of undefined
Last Comment
Jim Sokol

8/22/2022 - Mon
Ryan Chong

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
slightwv (䄆 Netminder)

For future reference, review this article on joins:

Then print and memorize the Venn Diagram at the bottom:
Jim Sokol

Thank you slightwv. 
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck