Reputation: 6410
SELECT * FROM emp WHERE emp.id
(BETWEEN 1000 AND 2000) OR IN ('3000','3001','4000')
How to write this type of query with combination of BETWEEN and IN clause in Oracle?
Upvotes: 0
Views: 194
Reputation: 754100
Repeat the column name (and don't use strings for numbers):
SELECT *
FROM emp
WHERE emp.id BETWEEN 1000 AND 2000 OR emp.id IN (3000, 3001, 4000)
You might want to bracket the whole OR term if there are other conditions AND'ed with it:
SELECT *
FROM emp
WHERE (emp.id BETWEEN 1000 AND 2000 OR emp.id IN (3000, 3001, 4000))
AND ...
There is nothing here that is specific to Oracle, either — just for once. You can apply it to any SQL DBMS.
Upvotes: 3