Tuesday, 2 August 2011

MySQL NOT IN query

I had to do this today to find all references that did not appear in a table. Here's a basic example;

SELECT player_id FROM tbl_player WHERE player_id NOT IN (SELECT player_ref FROM tbl_team);

How it works

The above example retrieves a list of all the players (player_ids) that do not appear in the team table (tbl_team) using the reference (player_ref).

No comments:

Post a Comment