[wd_asp elements=’search’ ratio=’100%’ id=1]

Distinct Sub Query – NOT IN

17th March 2014

MySql

mysql codehaven category

This code finds all records that campaign appears in both tables, then just shows one of each.

Table 1: – Blue, Red, Green, Red, Red

Table 2: – Blue, Red, Blue

Output: – Blue, Red (They appeared in both tables)

$query = "SELECT DISTINCT(campaign), client FROM table1 WHERE campaign NOT IN (SELECT campaign from targets where targets.campaign = cmdata.campaign)";