where子句中的多个PK

问题描述

在我的表中,我有LociD)这是我的PK,我试图将其范围缩小到特定的4,但是当我在下面运行查询时,我仅得到一个答案。该查询需要解决什么?

-- second we find out the name of the locations 

select name from location where Locid = 524 and 512 and 505 and 506 ; 

解决方法

使用WHERE IN可以更好地表达您要编写的查询:

select name from location where locid = in (524,512,505,506);

当前查询中实际发生的情况是,初始值(locid)后面的 上的524值被解释为字面真实。因此,您的查询与此相同:

select name from location where locid = 524 and true and true and true;

这当然与:

select name from location where locid = 524;

也就是说,您只会从匹配的524中获取记录。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...