我本来打算使用隐式联接来获得安吉丽娜·朱莉(Angelina Jolie)作为导演的所有电影,或者她是这部影片的主角
SELECT DISTINCT title, relYear
FROM actor,movie
WHERE director ='Angelina Jolie' OR aID in (SELECT aID
FROM actor
WHERE fName='Angelina' and surname='Jolie'
以下是相关表格
movie(id, title, relYear, category, runTime, director,
studioName, description, rating)
actor(aID, fName, surname, gender)
stars(movieID, actorID)
movGenre(movieID, genre)
这会返回所有电影,我认为是因为aID in (SELECT aID
我不知道如何在不对三个表使用显式联接的情况下执行此操作,即使子查询也是最有效的方法?谢谢
答案 0 :(得分:0)
这就是我要在MSSQL上执行的操作。认为它应该可以在MySql上工作。
Select title, relYear FROM movie WHERE director = 'Angelina Jolie' OR id IN
(SELECT movieId FROM stars inner join actor ON stars.actorId = actor.aID WHERE
actor.fName = 'Angelina' AND surname = 'Jolie')