Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude rows that don't join with another table?

Tags:

sql

join

I have two tables, one has primary key other has it as a foreign key.

I want to pull data from the primary table, only if the secondary table does not have an entry containing it's key. Sort of an opposite of a simple inner join, which returns only rows that join together by that key.

like image 922
Chaddeus Avatar asked Dec 30 '10 06:12

Chaddeus


1 Answers

alt text

SELECT <select_list>  FROM Table_A A LEFT JOIN Table_B B ON A.Key = B.Key WHERE B.Key IS NULL 

Full image of join alt text

From aticle : http://www.codeproject.com/KB/database/Visual_SQL_Joins.aspx

like image 179
Pranay Rana Avatar answered Sep 29 '22 14:09

Pranay Rana