acbugs Posted March 11, 2014 Share Posted March 11, 2014 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 https://forums.phpfreaks.com/topic/286884-problem-with-join-and-multiple-comparisons/ Share on other sites More sharing options...
acbugs Posted March 11, 2014 Author Share Posted March 11, 2014 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 https://forums.phpfreaks.com/topic/286884-problem-with-join-and-multiple-comparisons/#findComment-1472200 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.