Can we write conditions using both AND and OR?

Hello @sarahtlv,

Welcome to the forums!

Between the two choices presented above, the first one should be used.

An alternative would be to use the IN operator:

SELECT * 
FROM movies
WHERE genre IN ('action', 'comedy', 'romance')

You can read more about it here: IN Operator

6 Likes

I wonder if we can write this query shorter than it is works (without repeating word “genre”)
Instead of:
SELECT *
FROM movies
WHERE genre LIKE ‘romance’
OR genre LIKE ‘comedy’;

This:
SELECT *
FROM movies
WHERE genre LIKE ‘romance’
OR ‘comedy’;

Just to be clear, isn’t the question asking if we can combine both AND and OR operators? The AND in you example is AND used to specify range BETWEEN 10 AND 20 and also BETWEEN 50 AND 60 , no?

do you know html can you help me thanks

Unsure why you are asking this question here.
Please look in the proper forum threads for help regarding HTML, this is an SQL thread.
Besides that, when you ask a question please ask a specific question and give examples or the code you are working on so that people can help you better
Good luck

PUT SPACES IN YOUR CODE WHERE NEEDED. MAINTAIN READABILITY. SMH.

I tried this and sadly it didn’t work. Nice idea tho

Why cannt I just write like this

SELECT *
FROM movies
WHERE genre = 'romance'  OR  'comedy';

That’s the syntax for the condition.

WHERE genre = 'romance' OR genre = 'comedy'

Alternative:

WHERE genre IN ('romance', 'comedy')
2 Likes

Since noone replied to this, the values 10, 20, 50, 60 would NOT be included in the results because the statement is looking for value if field “id” to be greater than or less than the numbers on either side of the grouped AND

1 Like

Is this due to the sorting mechanism applied ?

> is not inclusive

>= is inclusive

Am I missing something here?

So what exactly does the word inclusive mean here?
/*
This will select movies with id values
from 10 to 20 inclusive, OR with id
values from 50 to 60 inclusive.
*/


(id >= 10 AND id <=20)
OR
(id >= 50 AND id <=60);

the original code is wrong....right? Am I missing something?

Here the values 10,20,50,60 will not be included in the Result. If we need that to be Inclusive we should have used:
SELECT *
FROM movies
WHERE
(id >= 10 AND id <= 20)
OR
(id >= 50 AND id <= 60);

Spot on!!

By the way, the relational operators order matters. If you type

id => 10 AND id =< 20

, it wont work.