SQL SELECT FIELDS IN A DIFFERENT TABLE -


i have 2 tables, 1 called orders , other 1 invoices. want know if have closed order without invoice. they're joined id_order, have this.

select  i.id_order,o.id_order invoices inner join orders o on o.id_order = i.id_order o.status='x' 

if o.id_order found in invoices means order invoiced. if o.id_order not found in invoices means not invoiced.

i want in select statement of orders not invoiced.

method1:

select *   order  id_order not in (select id_order invoices) 

method 2:

select  o.* orders o  left join invoices on o.id_order = i.id_order i.id_order null 

method 3:

select *  order o not exists (select id_order invoices i.id_order = o.id_order) 

stick first one, has better performance.


Comments