Explain Extended: SQL Explained
This series of articles is inspired by multiple questions asked by the site visitors and Stack Overflow users, including Tony, Philip, Rexem and others.
Which method (NOT IN vs. NOT EXISTS vs. LEFT JOIN / IS NULL) is best to select values present in one table but missing in another one?
This:
1.SELECTl.*2.FROMt_left l3.LEFTJOIN4.t_right r5.ONr.value = l.value6.WHEREr.valueISNULL, this:
1.SELECTl.*2.FROMt_left l3.WHEREl.valueNOTIN4.(5.SELECTvalue6.FROMt_right r7.)or this:
1.SELECTl.*2.FROMt_left l3.WHERENOTEXISTS4.(5.SELECTNULL6.FROMt_right r7.WHEREr.value = l.value8.)
source:
$link[host]
Read Original Source