nlvp
06-14-2004, 12:29 PM
I'm trying to select rows from one table where there are NO matching records in another. I can't seem to formulate a query that does this AND doesn't result in duplicates...
Table 1 : member
contains members with unique IDs (member.id)
Table 2 : photolink
is a many-to-many relationship intermediate table. So it contains photolink.member and photolink.photo. photolink.member refers to the member and photolink.photo refers to a record in a third table.
I need something that selects all the member records which do NOT have a corresponding record in photolink for a specific photo.
So something like :
SELECT member.* from member LEFT OUTER JOIN photolink ON photolink.member=member.id WHERE photolink.photo=217 GROUP BY member
but then trying to find a way to exclude the members where the corresponding record in photolink was actually found, and avoiding getting duplicate member records in the output.
Perhaps it's actually something like :
SELECT member.* from photolink LEFT OUTER JOIN member ON photolink.member=member.id WHERE photolink.photo=217 - although this selects exactly the opposite of what I want - all the members which are related to this photo, as opposed to those that aren't.
Any suggestions? Perhaps using an intermediate table, but I don't want to abuse the MySQL server too much.
Table 1 : member
contains members with unique IDs (member.id)
Table 2 : photolink
is a many-to-many relationship intermediate table. So it contains photolink.member and photolink.photo. photolink.member refers to the member and photolink.photo refers to a record in a third table.
I need something that selects all the member records which do NOT have a corresponding record in photolink for a specific photo.
So something like :
SELECT member.* from member LEFT OUTER JOIN photolink ON photolink.member=member.id WHERE photolink.photo=217 GROUP BY member
but then trying to find a way to exclude the members where the corresponding record in photolink was actually found, and avoiding getting duplicate member records in the output.
Perhaps it's actually something like :
SELECT member.* from photolink LEFT OUTER JOIN member ON photolink.member=member.id WHERE photolink.photo=217 - although this selects exactly the opposite of what I want - all the members which are related to this photo, as opposed to those that aren't.
Any suggestions? Perhaps using an intermediate table, but I don't want to abuse the MySQL server too much.