pwdrskier4 Posted May 31, 2006 Share Posted May 31, 2006 I have two tables (mls and geodata) that each have mls numbers as primary key. I am trying to return all off the records in table mls where the mls number does not have a row in geodata. My current statement is returning too many records. I have 8 records in mls and 3 records in geodata (all of which match an mls # in table mls) so I should get 5 records returned but instead get 21 (8 * 3 minus the 3 matches). Can anyone help?[code]SELECT mls.mls_num, geodata.geodata_mlsFROM mls, geodataWHERE mls.mls_num != geodata.geodata_mlsORDER BY mls_num ASC[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10886-need-help-with-sql-query/ Share on other sites More sharing options...
reandeau Posted May 31, 2006 Share Posted May 31, 2006 [!--quoteo(post=378795:date=May 31 2006, 11:21 AM:name=bill444)--][div class=\'quotetop\']QUOTE(bill444 @ May 31 2006, 11:21 AM) [snapback]378795[/snapback][/div][div class=\'quotemain\'][!--quotec--]I have two tables (mls and geodata) that each have mls numbers as primary key. I am trying to return all off the records in table mls where the mls number does not have a row in geodata. My current statement is returning too many records. I have 8 records in mls and 3 records in geodata (all of which match an mls # in table mls) so I should get 5 records returned but instead get 21 (8 * 3 minus the 3 matches). Can anyone help?[code]SELECT mls.mls_num, geodata.geodata_mlsFROM mls, geodataWHERE mls.mls_num != geodata.geodata_mlsORDER BY mls_num ASC[/code][/quote]Try something like this:SELECT mls.mls_num FROM mls LEFT JOIN geodata ON (mls.mls_num = geodata.geodata_mls) WHERE geodata.geodata_mls is NULL;Let me know how it goes.Jon Tjemsland Quote Link to comment https://forums.phpfreaks.com/topic/10886-need-help-with-sql-query/#findComment-40659 Share on other sites More sharing options...
pwdrskier4 Posted May 31, 2006 Author Share Posted May 31, 2006 [!--quoteo(post=378806:date=May 31 2006, 01:04 PM:name=Jon Tjemsland)--][div class=\'quotetop\']QUOTE(Jon Tjemsland @ May 31 2006, 01:04 PM) [snapback]378806[/snapback][/div][div class=\'quotemain\'][!--quotec--]Try something like this:SELECT mls.mls_num FROM mls LEFT JOIN geodata ON (mls.mls_num = geodata.geodata_mls) WHERE geodata.geodata_mls is NULL;[/quote]That totally worked, thank you so much. I actually had already solved my issue by dumping the #'s from the geodata table into an array and then comparing them to the #'s from mls table but this is much simpler. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/10886-need-help-with-sql-query/#findComment-40696 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.