0

I need some help. I've tried to search for the answer without success/

I need to select records from a table by price field which value must be in one of the ranges. Let me explain

select * from items 
    where color = 'black'
    AND shape = 'square'
    AND price between 333 and 444
    OR price between 777 and 888

But this will ignore color and shape conditions. What is the correct syntax for that? Is this a correct approach at all?

Thanks!

2 Answers 2

1

and has a higher operator precedence than or. You need parentheses to manage that

select * from items 
where color = 'black'
AND shape = 'square'
AND 
(
   price between 333 and 444
   OR price between 777 and 888
)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. That was a problem.
0

I think below useful to you. please check it once.

 select * from items 
        where color = 'black'
        AND shape = 'square'
        AND ((price between 333 and 444)
        OR (price between 777 and 888))

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.