Mysql deletes the record statement in the subquery _ MySQL

Source: Internet
Author: User
Mysql deletes the record statement bitsCN.com in the subquery.

Mysql deletes record statements in a subquery.

SQL code delete from t_5star where locationid in (select e. locationid from (select a. * from t_5star as a, t_als_data as B where a. term = B. term) e)

The key is to place the statements in the subquery into a single e table.

How to query and delete duplicate records

(1)

1. search for redundant duplicate records in the table. duplicate records are determined based on a single field (peopleId ).

SQL code select * from people where peopleId in (select peopleId from people group by peopleId having count (peopleId)> 1) 2. delete unnecessary duplicate records in the table, repeat Records are determined based on a single field (peopleId). only the records with the smallest rowid are retained: delete from peoplewhere peopleId in (select peopleId from people group by leleid having count (peopleId)> 1) and rowid not in (select min (rowid) from people group by peopleId having count (peopleId)> 1) 3. search for redundant duplicate records in the table (multiple fields) select * from vitae awhere (. peopleId,. seq) in (select peopleId, seq from vitae group by peopleId, seq having count (*)> 1) 4. delete redundant record (multiple fields) in the table ), delete from vitae awhere (. peopleId,. seq) in (select peopleId, seq from vitae group by peopleId, seq having count (*)> 1) and rowid not in (select min (rowid) from vitae group by peopleId, seq having count (*)> 1) 5. search for redundant duplicate records (multiple fields) in the table, excluding the records with the smallest rowid select * from vitae awhere (. peopleId,. seq) in (select peopleId, seq from vitae group by peopleId, seq having count (*)> 1) and rowid not in (select min (rowid) from vitae group by peopleId, seq having count (*)> 1)

(2)

For example

There is A field "name" in table ",

The "name" value may be the same for different records,

Now you need to query the records in the table, and the "name" value has repeated items; Select Name, Count (*) From A Group By Name Having Count (*)> 1. if the sex is also the same, Select Name, sex, Count (*) From A Group By Name, sex Having Count (*)> 1

BitsCN.com

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.