[英]SQL Server : two columns with the same row values in the same table
您應該使用自我聯接(由於表的尺寸,您可能需要在val和ecr上使用適當的分隔索引)
select a.*, b.*
from tableTest as a
inner join tableTest as b
on a.val = b.ecr
如果您不希望內部聯接的完整輸出,則可以使用如下所示的內容:
select *
from tableTest as t
where exists (
select 1
from tableTest as i
where t.val = i.ecr
)
除了聯接之外,另一個選項是子查詢:
SELECT *
FROM tableTest
WHERE val IN (SELECT ecr FROM tableTest)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.