1.表Information中有四个字段:ID,Name,Sex,Position ID为主键,现在想查找姓名一样的记录,sql语句应该写为:
select *
from Information
where Name in (
select Name from Information group by name having count(*)>1)
2.如果要查询姓名不同的记录,sql语句应该写为:
select *
from Information
where Name not in (
select Name from Information group by name having count(*)>1)
3.如果是查询记录数,只要将上述语句中的* 改为count(*)或count(Name),其中count(Name)比count(*)的效率要高.
检索出某个字段重复(或不重复)记录的SQL
最新推荐文章于 2021-09-10 17:32:36 发布