mysql中3个字段,如果这3个字段中,任何一个字段有重复值,则为重复,应该怎么写?
比如
a b c
1 2 3
4 5 3
c字段重复了,那么这两条记录就算重复。
我试了这个语句:
select distinct a,b,c from `table`
结果不对,查出来的是3个字段都相同才排除
而我要的是3个字段中任意一个字段的值相同就排除
等于说实现的效果跟把这3个字段设置成唯一键值一样的导量,查询这3个字段的值都为唯一的结果
回复内容: mysql中3个字段,如果这3个字段中,任何一个字段有重复值,则为重复,应该怎么写?
比如
a b c
1 2 3
4 5 3
c字段重复了,那么这两条记录就算重复。
我试了这个语句:
select distinct a,b,c from `table`
结果不对,查出来的是3个字段都相同才排除
而我要的是3个字段中任意一个字段的值相同就排除
等于说实现的效果跟把这3个字段设置成唯一键值一样的导量,查询这3个字段的值都为唯一的结果
但是你想查出什么呢…?比如1 2 3和1 4 3我应该留下哪个呢?这个查询的意义在哪里呢?
sql语句有点复杂:
select t1.a, t1.b, t1.cfrom demo as t1where t1.a not in ( select a from demo where t1.id != id )andt1.a not in ( select b from demo where t1.id != id )andt1.a not in ( select c from demo where t1.id != id )andt1.b not in ( select a from demo where t1.id != id )andt1.b not in ( select b from demo where t1.id != id )andt1.b not in ( select c from demo where t1.id != id )andt1.c not in ( select a from demo where t1.id != id )andt1.c not in ( select b from demo where t1.id != id )andt1.c not in ( select c from demo where t1.id != id )
select distinct id from ( select distinct a from table union select distinct b from table union select distinct c from table) as t