Reputation: 28384
Suppose I have a table such as the following:
movie_author | movie_name | movie_price
If I have the movie_name column value for a row, how would I make a query to get all movies with the same movie_author as the one in the row that contains the movie_name I have?
I could do this in two queries: the first getting the movie_author from the row that corresponds to the movie_name I have, and then the second getting all rows with the same movie_author, but how do I do this in one query?
Upvotes: 1
Views: 80
Reputation: 15758
For example, with IN
:
SELECT * from movies m2
WHERE m2.movie_author in (
SELECT m1.movie_author
FROM movies m1
WHERE m1.movie_name like '%AAA%'
)
Upvotes: 2
Reputation: 49049
You could use a join, like this:
SELECT m1.*
FROM movies m1 inner join movies m2
on m1.movie_author = m2.movie_author
and m2.movie_name='Movie name'
Upvotes: 2