sql查找同一个表中不同的字段

来源:百度知道 编辑:UC知道 时间:2024/09/21 08:52:57
假如一个表中有名称、用户名、类型、长度这几个字段,
我想查找这个表名称相同、类型相同但长度不一内容,
这该怎么查呀,特急,谢谢各位大侠
不行,自身连接会产生很多不同的

还是有好多的重复的列

楼上那个方法正确但是会出现重复记录

我给你改一下
select a.名称,a.类型,a.长度 from table1 a ,table1 b
where a.名称=b.名称 and a.类型=b.类型 and a.长度<>b.长度
group by a.名称,a.类型,a.长度

这样写行没?!
select distinct t1.name,t1.type,t1.length
from tablename as t1 inner join tablename as t2
on t1.name = t2.name
where t1.type = t2.type and t1.length <> t2.length
加个distinct去掉冗余项!
不过name,type,length这些关键字都不可以用作表名或字段(列)名的,这里只是为写着方便!

select a.* from table1 a ,table1 b where a.名称=b.名称 and a.类型=b.类型 and a.长度<>b.长度

select * from table group by 名称,类型,长度 having count(*) >1