Jump to content

[SOLVED] Two joined tables, but I only want 1 return from each result


MichaelMackey

Recommended Posts

Hi, heres my problem:

 

I have 2 tables I'm joining together.  The first table has user information such as their ID, name, etc.  The second table has test results for these users, the users can have multiple test results and it is also possible they will have no test results.  What determines if a user will have multiple test results is the year on the test (only one test result per user per year).

 

What I'm trying to do is select a list of ALL of the users, and if it's applicable it will also show their result data.  What I can't seem to figure out is how to select this data while ignoring the previous years data as well as ensuring all users are in the list even if they have no data.

 

This is what I'm currently trying to work with:

 

SELECT m.idcontestant, r.recognition FROM kn_contestant m LEFT JOIN kn_results_contestant r ON m.idcontestant = r.idcontestant WHERE (r.result_year = 2008 OR r.result_year IS NULL)

 

Any help is appreciated, thanks.

 

Mike

SELECT m.idcontestant, r.recognition 
FROM kn_contestant m 
    LEFT JOIN kn_results_contestant r ON m.idcontestant = r.idcontestant 
        AND ((r.result_year = 2008) OR (r.result_year IS NULL))

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.