I'm trying to write a MySQL Query which would find the titles of movies led by actors that have their names starting with B. I have got 2 tables, an Actor Table and Movie Table. In my Actor table, I've got the actID and actName, and in my Movie table, I've got the mvID, actID (FK), mvTitle, mvGenre, mvPrice, mvYear. I have already written a query for a similiar problem and I have tried to modify it for this query but it isn't exactly working. What I have so far is:
SELECT mvTitle
FROM Movie
WHERE EXISTS (SELECT mvGenre
FROM Movie,
Actor
WHERE (Actor.actID = Movie.actID)
and (Actor.actName LIKE 'B%'))
Which returns all of the movie titles rather than returning the specific ones (as it should only return 3 titles) but returns all of the 10 titles.
SELECT DISTINCT m.mvTitle from Movie m JOIN Actor a on a.actId = m.actId WHERE a.actName LIKE 'B%'
尝试一下...我选择使用联接而不是子选择-对我来说似乎更干净。
use correlated subquery
SELECT mvTitle
FROM Movie a
WHERE EXISTS (SELECT 1
FROM Actor b
WHERE a.actID = b.actID
and b.actName LIKE 'B%')
SELECT mvTitle
FROM Movie where actID in (select actID from Actor where actName LIKE 'B%')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.