Look at the SQL original intention is to delete user id duplicate records goods, is clearly wrong, because the subquery is wrong, truth is
The delete from the table where id in (select from b (select Max (id) as b from the table where user_id=xx group by goods_id having count (goods_id) & gt; 1) a);
Personal struggle is not that, is SQL subquery is clearly wrong, but the real operation on the mysql logic is: when the user_id=xx is a record, to delte full table, analysis for a long time, don't know what's going on,
Remind, if I am careful, should check out the subquery, direct error is not the tragic
CodePudding user response:
Should not be performed,CodePudding user response:
Clearer complex SQL execution step by stepCodePudding user response:
Perform a select id from (select Max (id) from the table where user_id=xx group by goods_id having count (goods_id) & gt; 1) a lookCodePudding user response:
Pay attention to your Max (id) is not namedSelect id from (select Max (id)
-- -- -- -- -- -- -- -- this id is actually take the outer table id, because you have no id the column in the subquery, so since the straton queries have a record, then the results of this query is=outer id, id clearly meet the conditions in (select id
So not to delete a full table is wrong instead of
CodePudding user response:
In general, in the specification of the DBA, table will be asked to write clearly the name of the table, in order to avoid this kind of dog blood event, but that most programmers don't careCodePudding user response:
The