Reputation:
I have movie
as my table
I tried to execute the following queries where put in 2 conditions with movie_genre='comedy'
and movie_genre='family'
:
select movie_title, movie_cost, movie_genre
from movie
where movie_genre ='comedy'
and movie_genre ='family'
order by movie_cost asc;
After executed the queries it return Empty set
.
While I tried one condition it works normally but when adding 2 conditions it goes wrong again.
How can I solve this problem?
Upvotes: 1
Views: 169
Reputation: 42622
One more option is UNION ALL:
SELECT movie_title, movie_cost, movie_genre
FROM movie
WHERE movie_genre = 'comedy'
UNION ALL
SELECT movie_title, movie_cost, movie_genre
FROM movie
WHERE movie_genre = 'family'
ORDER BY movie_cost ASC;
Upvotes: 0
Reputation:
You have to use OR
to check if movie_genre
is either of the two values.
Updated query -
select movie_title, movie_cost, movie_genre from movie
where movie_genre ='comedy' or movie_genre ='family'
order by movie_cost asc;
Upvotes: 2
Reputation: 57573
SELECT movie_title, movie_cost, movie_genre
FROM movie
WHERE
movie_genre ='comedy'
OR
movie_genre ='family'
ORDER BY movie_cost ASC;
You should use OR
because AND
means that the two conditions must be true at the very same time, but that's impossible!
A different query syntax could be
SELECT movie_title, movie_cost, movie_genre
FROM movie
WHERE movie_genre IN ('comedy', 'family')
ORDER BY movie_cost ASC;
Upvotes: 1