Jump to content

Problem with JOIN and multiple comparisons


acbugs
Go to solution Solved by acbugs,

Recommended Posts

Hi all,

 

I've been struggling with this bit of code for a while, and I need help!

 

I have two tables, and I'm trying to do a LEFT OUTER JOIN where values found in the first table but not in the second table will be printed to the screen.

 

However, I also need to compare some other submitted variables (year, outcomenumber, unitnumber) so that the result is narrowed down.

 

This code is giving me the opposite of what I want, and I can't seem to tweak it to get the results I need.  warehouselogin is a list of all instructors, and warehousedatains is a list of submitted data by instructors.  I want to check to see which instructors have not submitted data for a certain year and outcome number and print those to the screen.

 

$r = mysql_query("SELECT * FROM warehouselogin LEFT OUTER JOIN warehousedatains on warehouselogin.instructor_password = warehousedatains.instructor_password && warehousedatains.unitnumber='$unitnumber' && warehousedatains.year='$year' && warehousedatains.outcomenumber='$outcomenumbercheck' WHERE warehousedatains.instructor_password IS NOT NULL GROUP BY warehouselogin.InstructorName ASC");
 

Thanks so much for any suggestions!

Link to comment
Share on other sites

  • Solution

To anyone else who needs help with a similar problem, this is the query I used to give me the results I needed in a PHP script.

 

$r = mysql_query("SELECT * FROM warehouselogin WHERE unitnumber='$unitnumber' && warehouselogin.instructor_password NOT IN (SELECT warehousedatains.instructor_password FROM warehousedatains WHERE unitnumber='$unitnumber' && outcomenumber='$outcomenumbercheck')");
 

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.