Jump to content

Recommended Posts

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_mls
FROM mls, geodata
WHERE mls.mls_num != geodata.geodata_mls
ORDER BY mls_num ASC[/code]
Link to comment
https://forums.phpfreaks.com/topic/10886-need-help-with-sql-query/
Share on other sites

[!--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_mls
FROM mls, geodata
WHERE mls.mls_num != geodata.geodata_mls
ORDER 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
[!--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!
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.