不錯的mysql聯表多表查詢 mysql聯表多表查詢,以前查詢的時候,可以直接select * from tablea as a ,tableb.as b where a.cc=b.cc.今天分享一個新奇的寫法,而且對於百W數據執行效率可是相當的快,下面分享一下聯表多表查詢的幾個語句: www.2cto.com SQL代碼 #在Tbl_User中刪除非法積分數據的QQ的邀請好友QQ資料 delete from Tbl_User where FQQ IN (select FDesQQ from Tbl_InviteHistory where FSrcQQ IN (select DISTINCT(FSrcQQ) from Tbl_ScoreDetail where FScore>'250' and FStrategy='4')) #在Tbl_User中刪除非法積分數據的QQ資料 delete from Tbl_User where FQQ IN (select DISTINCT(FSrcQQ) from Tbl_ScoreDetail where FScore>'250' and FStrategy='4') #在Tbl_InviteHistory中刪除所有非法積分數據的邀請記錄 delete from Tbl_InviteHistory where FSrcQQ IN (select DISTINCT(FSrcQQ) from Tbl_ScoreDetail where FScore>'250' and FStrategy='4') www.2cto.com #在Tbl_Score中刪除非法積分數據的總積分 delete from Tbl_Score where FQQ IN (select DISTINCT(FSrcQQ) from Tbl_ScoreDetail where FScore>'250' and FStrategy='4') #在Tbl_ScoreDetail中刪除非法積分明細 delete from Tbl_ScoreDetail where FScore>'250' and FStrategy='4' www.2cto.com #刪除Tbl_Score表裡沒有Tbl_User的用戶 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) //查兌換碼大於20的用戶明細表 SELECT FQQ,FCode,FApplyTime FROM Tbl_Code where FQQ in (SELECT a.FQQ FROM (SELECT COUNT(*) as num,FQQ FROM `Tbl_Code` GROUP BY FQQ HAVING num>20) as a) and FStatus='1'