在我的表中,我有 (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 ;
在我的表中,我有 (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
RHS 上第一个 ( )之后524
的值被解释为字面真值。因此,您的查询与此相同:
select name from location where locid = 524 and true and true and true;
这当然与以下内容相同:
select name from location where locid = 524;
也就是说,您只会从匹配中获取记录524
。