让我们假设如下:
表A
id | value
----------
1 | red
2 | orange
5 | yellow
10 | green
11 | blue
12 | indigo
20 | violet
我有一个id列表(10, 11, 12, 13, 14
),可以用来在这个表中查找id.这个id列表是在我的前端生成的.
Using purely SQL, I need to select the id's from this list (10, 11, 12, 13, 14
) that do not have entries in 表A (joining on the 'id' column). The result should be the resultset of id's 13
and 14
.
仅使用SQL如何实现这一点?(另外,如果可能的话,我希望避免使用存储过程)
我能想到的唯一方法是动态创建一个内联SQL表来临时保存我的id列表.然而,我不知道如何做到这一点.这可能吗?有更好的办法吗?
谢谢!:)