Julian Hansen Julian Hansen - 7 months ago 27
SQL Question

List names of directors

SELECT DISTINCT director.lastname, director.firstname
FROM director LEFT JOIN movdir ON director.dirnum = movdir.dirnum


This is what I have right now, but I have to look at a
movdir
table and see if
dirnum(director number)
only shows up once. If it does, I have to go to the
director
table and see what their name is by looking at
dirnum
and see whose name is attached to that number.

Answer

You could use GROUP BY with HAVING-clause:

SELECT director.lastname, director.firstname
FROM director 
INNER JOIN movdir ON director.dirnum = movdir.dirnum
GROUP BY director.lastname, director.firstname
HAVING COUNT(*) = 1