当前位置: 代码迷 >> PHP >> php 怎么检测一个数据库字段是否是唯一的
  详细解决方案

php 怎么检测一个数据库字段是否是唯一的

热度:236   发布时间:2016-04-28 19:00:20.0
php 如何检测一个数据库字段是否是唯一的
订单数据库
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 id,dan,money,count(*) as num from ssc_record  group by dan having num > 1
  相关解决方案