Delete the same student redundancy information except the ID number

Source: Internet
Author: User

Delete The same student redundancy information except the ID number
2. The student table is as follows :
ID number Study number name course number Course name score
1 2005001 Zhang San 0001 Mathematics 69
2 2005002 John Doe 0001 Mathematics 89
3 2005001 Zhang San 0001 Mathematics 69

Create TableStudent2 (IDintAuto_incrementPrimary Key, codevarchar( -), namevarchar( -));Insert  intoStudent2Values(NULL,'2005001','Zhang San'),(NULL,'2005002','John Doe'),(NULL,'2005001','Zhang San');//in the following statement, MySQL reports errors and may delete dependent statistical statements, which in turn result in inconsistent statistical statement results. Delete  fromStudent2whereId not inch(Select min(ID) fromStudent2Group  byname);//However, there is no problem with the following statement:Select *  fromStudent2whereId not inch(Select min(ID) fromStudent2Group  byname);//So, I want to first put the result of the group into a virtual table, and then select the result from the virtual table, and finally the result as the deletion of the condition data. Delete  fromStudent2whereId not inch(SelectMid from(Select min(ID) Mid fromStudent2Group  byName ast); or:Delete  fromStudent2whereId not inch
(Select min(ID) from
(

Select * fromStudent2) asTGroup byT.name);

Delete the same student redundancy information except the ID number

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.