sql – 如何有效地选择所有重复项

前端之家收集整理的这篇文章主要介绍了sql – 如何有效地选择所有重复项前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想选择具有表中已存在的值的所有行.我找不到更好的解决方
select * 
from provisioning_requests tt 
where code in (select code 
               from provisioning_requests tt2 
               where tt2.id <> tt.id)

这似乎有点幼稚.有人有更好的解决方案吗?

解决方法

select * 
from provisioning_requests t1
 join (select code from provisioning_requests group by code having count(*)>1) t2
 ON t1.code = t2.code

要么

select * 
from provisioning_requests
 WHERE code in (select code from provisioning_requests group by code having count(*)>1)
原文链接:https://www.f2er.com/mssql/78286.html

猜你在找的MsSQL相关文章