Mysql development skills-JOIN update and data re-checking/de-duplicating; development skills-join

Source: Internet
Author: User

Mysql development skills-JOIN update and data re-checking/de-duplicating; development skills-join

Mainly involved: JOIN, JOIN update, group by having data re-query/de-duplication

1 inner join, left join, right join, full join (not supported by MySQL), CROSS JOIN

This is a very good blog post on the Internet. The join statement is illustrated as follows:

CODING HORROR-A Visual Explanation of SQL Joins

We can clearly understand the range of join data selection.

[] [1]
[1]: http://7xs09x.com1.z0.glb.clouddn.com/160725-imooc-mysql-development-skills-notes-001.png

2. Update the tables included in the filtering conditions.

Update repeated fields of col_a in Table t1 and t2

UPDATE t1 SET col_a = 'hi' WHERE t1.col_a IN ( SELECT b.col_a FROM t1 a INNER JOIN t2 b on a.col_a = b.col_a);ERROR:1093 

Convertible:

UPDATE t1 aa JOIN( SELECT b.col_a FROM t1 a INNER JOIN t2 b on a.col_a = b.col_a)bb on aa.col_a= bb.col_aSET col_a = 'hi' ;

3. query and delete duplicate data

Query duplicate data using group by and HAVING

SELECT col_a, COUNT(*)FROM t1GROUP BY col_a HAVING COUNT(*) > 1;

Delete duplicate data.

DELETE aFROM t1 a JOIN ( SELECT col_a,COUNT(*),MAX(id) AS id FROM t1 GROUP BY col_a HAVING COUNT(*) > 1)b ON a.col_a = b.col_aWHERE a.id < b.id;

Thank you for reading this article and hope to help you. Thank you for your support for this site!

Related Article

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.