Reputation: 1235
I have a query say
SELECT name,number FROM TABLE WHERE number='123'
What I want is to display multiple records using where clause or any other way so that I can get following data.
Name Number
ABC 123
PQR 127
PQR 130
I tried using AND
&&
,
in where clause.i.e.
where number=123,127,130
or where number=123 AND 127 AND 130
etc. but nothing works.
Upvotes: 7
Views: 57512
Reputation: 1
you can use where in to get multi record like this,
select * from table name
WHERE COLUMN_NAME IN ('12','23','43','46');
Result will be :
COLUMN_NAME
12
23
43
46
Upvotes: -1
Reputation: 60493
just use an IN
clause
where number in (123, 127, 130)
you could also use OR (just for info, I wouldn't use this in that case)
where number = 123 or
number = 127 or
number = 130
Don't forget round braces around the "ors" if you have other conditions in your where clause.
Upvotes: 13
Reputation: 18600
Try this
SELECT name,number FROM TABLE WHERE number IN (123,127,130);
OR
SELECT name,number FROM TABLE
WHERE number = 123
OR number = 127
OR number = 130;
Upvotes: 2