首頁  >  文章  >  後端開發  >  php 怎么检测一个数据库字段是否是唯一的

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

WBOY
WBOY原創
2016-06-13 12:00:441368瀏覽

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

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn