How does php check whether a database field is unique?

Source: Internet
Author: User
How does php check whether a database field is a unique order database?
Id dan money
01 0001a 5
02 0001a 5
03 0001a 5
04 0001b 5
05 0001c 5
How can I check whether an order number is duplicated?
If all data is listed
For example, the upper column
List
01 0001a 5
02 0001a 5
03 0001a 5

How do I write mysql statements?


Reply to discussion (solution)

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

It should be about the database: oracle: select * from t where dan in (select dan from t where having count (dan)> 1 group by dan ).

Well, SELECT * from ssc_record WHERE types = 7 and dan1 in (SELECT dan1 from ssc_record group by dan1 HAVING count (1)> 2)
In this way, the query is slow. if the data volume is large, it will not change.

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.