vishalkin
vishalkin

Reputation: 1235

SQL Where Clause with multiple values

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 130etc. but nothing works.

Upvotes: 7

Views: 57512

Answers (3)

Kishor Shivaji
Kishor Shivaji

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

Raphaël Althaus
Raphaël Althaus

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

Sadikhasan
Sadikhasan

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

Related Questions