Developer
Developer

Reputation: 847

use multiple between clause for same column

I want to use multiple between clause for same clause.

I tried the following query but its not working

select id from test where 
(id between 11123745 and 11182111)
and (id between 11182962 and 11182968)
and (id between 11183172 and 11183176)

My query returning nothing , how can i make this query work?

Upvotes: 0

Views: 772

Answers (2)

andy
andy

Reputation: 2002

Your intervals are not overlapping and therefore, combining them with AND does not leave any id to be matched. Combine them using OR like this:

SELECT id FROM test 
WHERE 
  (id BETWEEN 11123745 AND 11182111)
  OR (id BETWEEN 11182962 AND 11182968)
  OR (id BETWEEN 11183172 AND 11183176)

Upvotes: 2

HLGEM
HLGEM

Reputation: 96572

It is not physically possible to meet those conditions under any circumstances. You need to use OR.

Upvotes: 1

Related Questions