Home > database >  Request under the optimized SQL
Request under the optimized SQL

Time:10-11

Bz_post
Id, uid, title
Bz_post_content
Id, the content

 

The delete from bz_post_content WHERE ID IN (

SELECT from Anderson, d bz_post a
Left the join bz_post_content c on Anderson, d=c.i d
Where
Anderson, d & lt;>
(
The select min (b.i d) from bz_post b
Left join on b.i bz_post_content d d=d.i d
Where a.u id=b.u id and a.t itle=b.t itle and Arthur c. ontent=, dc ontent

)
);

I write very trouble is to delete the same uid under the same title and content but retain a
Now the SQL slowly out of the sky don't know much about SQL

CodePudding user response:

With the EXPLAIN output execution plan, take a look at,

CodePudding user response:

I understand you are the first refers to id the smallest
 
The delete
The from
Bz_post_content t1
Where the exists (
Select 1 from bz_post_content t2 where t1. The uid=t2. The uid and t1. The title=t2. The title and t1. The content=t2. The content and t2. Id)

CodePudding user response:

Along the way, when processing SQL is the most important still facing a collection of thoughts, not lines in that line, to find if it meets the requirements of xx just one-time find accords with a condition that collection, if from the program to turn the DBA to spend a long time to overcome the existing fixed ways of thinking,

CodePudding user response:

You mean should be to heavy line, you can refer to:
https://blog.csdn.net/weixin_39540651/article/details/106387049
  • Related