1

Hi all i'm currently doing some SQL homework and am looking for a push in the right direction. I need to display a list of directors that have never worked in a paramount picture movie.

select distinct directorID
from movieinfo natural join directinfo
where studio <> 'Paramount Picture';

This displays both directors who never have, as well as directors who have worked for paramount and also done another job with someone else.

I thought maybe an EXISTS sub query would help me but i ended up with the exact same result.

Would anyone know a way to check if directer EVER worked with paramount and to cross them off the list?

EDIT** DirectorID does not belong in both tables. directinfo(mvid, directorID) movieinfo(mvid, title, rating, year, length, studio)

4

2 回答 2

1

您可以使用以下内容:

SELECT directorID FROM directinfo WHERE directorID NOT IN 
    (SELECT directorID FROM movieinfo WHERE studio='Paramount Picture');

这将为您提供派拉蒙影业工作室未涉及的所有导演 ID。

编辑:删除了错误的第二个答案。

于 2013-05-27T05:29:24.907 回答
1

试试这个EXISTS

SELECT  a.*
FROM    directinfo a
WHERE   NOT EXISTS
        (
            SELECT  1
            FROM    movieinfo b
            WHERE   a.directorID = b.directorID AND
                    b.studio <> 'Paramount Picture'
        )

这假设该列studio属于 tablemovieinfo并且两个表都包含directorID.

另一种方法是使用LEFT JOIN...IS NULL,

SELECT  a.*
FROM    directinfo a
        LEFT JOIN movieinfo b
            ON  a.directorID = b.directorID AND
                b.studio <> 'Paramount Picture'
WHERE   b.directorID IS NULL
于 2013-05-27T05:29:28.087 回答