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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.