Forum Moderators: open
You can use a NOT IN clause for this. Essentially you want to select rows from ONE where the primary key (fieldm in my examples below) for ONE is NOT IN TWO:
SELECT field1,field2,...,fieldn
FROM One
WHERE fieldm NOT IN (
SELECT fieldm FROM Two
)
NOT INs are not the most efficient clauses around. If you are dealing with very large tables and columns that are not indexed, it can run a long time.
The same thing can be accomplished with an OUTER JOIN. I don't have MySQL but off of the top of my head (without testing it) you could do something along the lines of:
SELECT field1, field2, ... , fieldn
FROM One AS o
LEFT JOIN Two AS t ON o.fieldm = t.fieldm
WHERE t.fieldm IS NULL
This should give you back rows from One that do not already exist in Two. Again this assumes that fieldm is the primary key for both tables.
[edited by: ZydoSEO at 1:38 pm (utc) on Sep. 22, 2008]