Good mysql multi-table join query _ MySQL

Source: Internet
Author: User
Nice mysql Union table multi-table query bitsCN.com

Good mysql multi-table query

For mysql multi-table queries, you can directly select * from tablea as a, tableb. as B where. cc = B. cc. today, I will share a novel way of writing, and the execution efficiency of hundreds of thousands of data is quite fast. Here are some statements for multi-table queries:

SQL code

# Information about QQ invitations for deleting illegal credit data from Tbl_User

Delete from Tbl_User where FQQ IN

(Select FDesQQ from Tbl_InviteHistory where FSrcQQ IN

(Select DISTINCT (FSrcQQ) from Tbl_ScoreDetail where FScore> '20180101' and FStrategy = '4 '))

# Delete QQ information of illegal credit data from Tbl_User

Delete from Tbl_User where FQQ IN

(Select DISTINCT (FSrcQQ) from Tbl_ScoreDetail where FScore> '20180101' and FStrategy = '4 ')

# Delete the invitation records for all invalid points in Tbl_InviteHistory

Delete from Tbl_InviteHistory where FSrcQQ IN

(Select DISTINCT (FSrcQQ) from Tbl_ScoreDetail where FScore> '20180101' and FStrategy = '4 ')

# Delete the total points of invalid points in Tbl_Score

Delete from Tbl_Score where FQQ IN

(Select DISTINCT (FSrcQQ) from Tbl_ScoreDetail where FScore> '20180101' and FStrategy = '4 ')

# Delete invalid points in Tbl_ScoreDetail

Delete from Tbl_ScoreDetail where FScore> '2013' and FStrategy = '4'

# Delete users without Tbl_User in the Tbl_Score table

Delete from Tbl_Score where FQQ not IN (select FQQ from Tbl_User)

Delete from Tbl_ScoreDetail where FSrcQQ not IN (select FQQ from Tbl_User)

// Query the user list with a redemption code greater than 20

Select fqq, FCode, FApplyTime FROM Tbl_Code where FQQ in (SELECT. fqq from (select count (*) as num, fqq from 'tbl _ code' group by fqq having num> 20) as a) and FStatus = '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.