Heim  >  Artikel  >  Backend-Entwicklung  >  php 怎么检测一个数据库字段是否是唯一的

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

WBOY
WBOYOriginal
2016-06-13 12:00:441368Durchsuche

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

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn