PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

php 如何检测一个数据库字段是否是唯一的

原创
2016-06-23 13:54:46 858浏览

订单数据库
id  dan        money
01 0001a   5
02 0001a   5
03 0001a   5
04 0001b   5
05 0001c   5
如何检测一个订单号是否是有重复的
如果有列出所有数据
如上列
列出
01 0001a   5
02 0001a   5
03 0001a   5

mysql语句该怎么写?


回复讨论(解决方案)

 select * from tt t where exists (select 1 from tt where dan=t.dan and id !=t.id);

应该是关于数据库的问题:oracle:select * from t where dan in  (select dan from t where having count(dan)>1 group by dan)。

恩,SELECT * from ssc_record WHERE types = 7 and dan1 in(SELECT dan1 from ssc_record GROUP BY dan1 HAVING count(1)>2) 
这样查询起来好慢阿 数据量大就卡在那不会动了。

select id,dan,money,count(*) as num from ssc_record  group by dan having num > 1

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。