2

Im doing a few exersices for the my head around SQL queries. Im trying to achieve all items( partno) that haven't been ordered. This is a below diagramenter image description here

What im trying to achieve is the Full List of partno's from the parts table minus the Partno from the OrderedItems Table. I beleive i would need to do a Left Outter Join.

Like Below

SELECT *
FROM PARTS, ORDEREDITEMS
LEFT OUTER JOIN ordereditems.Partno - parts.Partno;

Still a bit stuck on this one, is this the right track on this?

Buzzy
  • 45
  • 7

3 Answers3

3
select * 
from parts 
where partno not in ( select partno from ordereditems)

Simply select all that are not in the other table.

select * 
from parts 
where not exists ( select 1 from ordereditems where partno = parts.partno) 

would be an alternate way of doing it.

Patrick Artner
  • 50,409
  • 9
  • 43
  • 69
1
select Parts.*
from Parts left join Ordereditem
on Parts.partno = Ordereditem.partno
where Ordereditem.partno is null
kc2018
  • 1,440
  • 1
  • 8
  • 8
0

try this

select a.partno - b.partno from
(select * from PARTS) as a
left JOIN
(select * from ORDEREDITEMS) as b
on a.Partno = b.Partno
Vijunav Vastivch
  • 4,153
  • 1
  • 16
  • 30