![](/img/trans.png)
[英]T-SQL How to select count of one column's values where another column's values are the same
[英](SQL) Select rows only where a column's values are found in another column?
是的,通过对同一张表进行 INNER JOIN,匹配不同列的值并使用 DISTINCT 保持结果的唯一性(因为可能有多个指向相同名称的指针):
SELECT DISTINCT a.*
FROM mytable a INNER JOIN mytable b ON a.name = b.pointer
这里你 Go,使用 selg 连接:
Create table #temp( name varchar(200), ColumnA int, PointerColumnB int)
Insert into #temp values('NAMEA',1,null),('NAMEB',2,3),
('NAMEC',3,3),('NAMED',4,null),('NAMEE',5,4),('NAMEF',6,7),('NAMEG',7,null)
Select distinct x.Name
from #temp x
join #temp y on x.ColumnA = y.PointerColumnB
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.