CoderZone.org

Category: >> mySQL >> Inverted UNION (the opposite of UNION) Bookmark and Share

<< lastnext >>

Snippet Name: Inverted UNION (the opposite of UNION)

Description: This finds all rows in table_1 with an ID that isn't present in table_2. In other words, it finds all rows in table_1 with no matching row in table_2. This relies on table_2's ID field as being declared NOT NULL.

Also see:
» Match all #RRGGBB or #RGB values i...
» BR2NL Function - Opposite of NL2BR
» Opposite of mysql_fetch_assoc
» Get ordered list of near match ite...
» Select or match a range of dates
» Regex Matching Patterns
» mySQL Fake Union Code

Comment: (none)

Author: CoderZone
Language: MYSQL
Highlight Mode: MYSQL
Last Modified: February 26th, 2009

SELECT table_1.* FROM table_1 
     LEFT JOIN table_2 ON table1.id=table_2.id
WHERE table_2.id IS NULL;
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 11