MySQL Development skills join update and data check weight/GO heavy _mysql

Source: Internet
Author: User

Mainly involved: Join, join update, GROUP by have data check weight/GO heavy

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

This is a very good post that is found on the web, illustrated by the join statement:

Coding horror-a Visual explanation of SQL joins

The following figure makes it clear that the data selection for join

[][1]
[1]: Yun_qi_img/160725-imooc-mysql-development-skills-notes-001.png

2 Update uses the filter condition to include its own table

Update col_a duplicate fields in the T1 T2 table

UPDATE T1 
SET col_a = ' Hi ' 
WHERE t1.col_a in (
 SELECT b.col_a to T1
 a INNER JOIN T2 b on
 a.col_a = b . col_a
)
;
error:1093 

can be converted to:

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.C Ol_a
SET col_a = ' Hi ' 
;

3 Querying for duplicate data, deleting duplicate data

Using GROUP by and having queries for duplicate data

SELECT col_a, COUNT (*) from
T1
GROUP by Col_a has count (*) > 1
;

Delete duplicate data, for the same data retention ID maximum

DELETE a
from T1 a JOIN (
 SELECT col_a,count (*), MAX (ID) as ID from
 T1
 GROUP by col_a have COUNT (*) > 1
b on a.col_a = b.col_a
WHERE a.id < b.id
;

Thank you for reading this article, I 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.