mySQL outer join

Señor Reginold Francis picture Señor Reginold Francis · Oct 12, 2010 · Viewed 10.8k times · Source

I have 2 tables for which I need to run a query on

Table1 has 2 fields: l_id, and name

Table2 also has 2 fields: l_id, and b_id

I need to run a query to get the "name" and "l_id" for all the entries in table1 that do not have an entry in table2 for a given b_id.

Hope this makes some sense

Answer

D'Arcy Rittich picture D'Arcy Rittich · Oct 12, 2010
select t1.*
from Table1 t1
left outer join Table2 t2 on t1.l_id = t2.l_id
    and t2.b_id = @SomeValue
where t2.l_id is null