![](/img/trans.png)
[英]How to can I use a SQL query column in as the arguments of a where clause?
[英]How to use SQL query with a column of values for where?
如何在第二個 select 查詢中使用 WHERE 創建一列 ID。
要循環的 id 示例表:
這是我到目前為止得到的:
WITH myTable
AS (
select myKey as myKey
from dbo.table
Where column2 = 'x'
GROUP BY myKey
)
SELECT *
FROM table2
WHERE table2.key = myKey
我無法使用我的值列遍歷 table2。 我該怎么做?
您可以in
:
SELECT *
FROM table2
WHERE table2.key IN (SELECT mt.myKey FROM myTable mt);
鑒於mykey
是唯一的,您還可以使用JOIN
和EXISTS
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.