SQL Where子句具有多个值 [英] SQL Where Clause with multiple values
问题描述
我有一个查询说
SELECT name,number FROM TABLE WHERE number='123'
我想要的是使用where子句或其他任何方式显示多个记录,以便获得以下数据.
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.
姓名号码
ABC 123
PQR 127
PQR 130
Name Number
ABC 123
PQR 127
PQR 130
我尝试在where子句中使用AND
&&
,
where number=123,127,130
或where number=123 AND 127 AND 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.
推荐答案
只需使用IN
子句
where number in (123, 127, 130)
您还可以使用OR(仅用于提供信息,在这种情况下,我不会使用此功能)
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
如果where子句中有其他条件,请不要忘记在或"周围加上圆括号.
Don't forget round braces around the "ors" if you have other conditions in your where clause.
这篇关于SQL Where子句具有多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!