-1

在我的表中,我有 (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 ; 

4

1 回答 1

2

您打算编写的查询可以更好地表达为WHERE IN

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

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

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

这当然与以下内容相同:

select name from location where locid = 524;

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

于 2020-08-18T04:15:58.880 回答