Reputation: 971
I have a table with columns ID(primary key,number), name(varchar), value(number) and key(number).I want to retrieve all the records which have key=1 and key=2. I can write the query using not equals condition(!=) but this makes the query very long.This is what I tried
SELECT * FROM USER_DETAILS WHERE NAME='sam' AND
KEY != 3 AND KEY != 4 AND KEY != 5 AND KEY != 6 AND KEY != 7 AND KEY != 8 AND
so on.Could you suggest me an Oracle query where I can retrieve the records that have key=1 and key=2 rather than checking for not equals condition.
UPDATE: As suggested in the answer I want to know if IN is supported in Hibernate
Upvotes: 0
Views: 117
Reputation: 4476
IN OPERATOR is supported in Hibernate. The query you should write to solve your problem is:
SELECT * FROM USER_DETAILS WHERE NAME='sam' AND KEY IN (1,2)
Upvotes: 3
Reputation: 3852
SELECT * FROM USER_DETAILS
WHERE
KEY=1 OR KEY=2
Or
SELECT * FROM USER_DETAILS
WHERE
KEY IN (1,2)
Upvotes: 3