[英]How to use SQL query with a column of values for where?
How can I loop though a column of IDs I created with in a 2nd select query with a WHERE.如何在第二个 select 查询中使用 WHERE 创建一列 ID。
Example table of ids to loop through:要循环的 id 示例表:
Here is what I got so far:这是我到目前为止得到的:
WITH myTable
AS (
select myKey as myKey
from dbo.table
Where column2 = 'x'
GROUP BY myKey
)
SELECT *
FROM table2
WHERE table2.key = myKey
I can't loop through table2 with my column of values.我无法使用我的值列遍历 table2。 How can I do it?
我该怎么做?
You can use in
:您可以
in
:
SELECT *
FROM table2
WHERE table2.key IN (SELECT mt.myKey FROM myTable mt);
Given that the mykey
is unique, you can also use JOIN
and EXISTS
.鉴于
mykey
是唯一的,您还可以使用JOIN
和EXISTS
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.