1

i have these tables:

  • tblstaff (staff_id, SName, Department)
  • tblorder (order_id, orderdate, cus_id, tootalAmount, staff_id)

i want to display all names and department of staffs who did not approve an order. The code below shows me empty set.

SELECT s.SName, s.Department from tblstaff s 
INNER JOIN tblorder o
on s.staff_id=o.staff_id
WHERE o.order_id is Null;
  • http://stackoverflow.com/questions/5706437/whats-the-difference-between-inner-join-left-join-right-join-and-full-join – crafter Apr 09 '15 at 15:36

1 Answers1

0

inner join will only give you results when items from table a and table b match. What you want is left join.

SELECT s.SName, s.Department 
from tblstaff s 
LEFT JOIN tblorder o
on s.staff_id=o.staff_id
WHERE o.order_id is Null;

This will give you all results from tblstaff, even if they have no match in tblorder.

Mackan
  • 6,200
  • 2
  • 25
  • 45