Home  >  Article  >  Backend Development  >  php 怎么检测一个数据库字段是否是唯一的

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

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

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn