The barcode value that would have been deleted in the Error_barcode table is repeated only one table structure as follows (Ps:id is self-growing, the figure is deleted successfully so ID is not contiguous)
The SQL statements are as follows:
DELETE fromError_barcodeWHEREBarCodeinch ( SELECTBarCode fromError_barcodeGROUP byBarCode having Count(BarCode)> 1 ) andId not inch ( SELECT min(ID) fromError_barcodeGROUP byBarCode having Count(BarCode)> 1)
But it's a mistake.
Surfing the internet to find the next, this is a problem with MySQL, is no longer in the same statement to the same table first select some values in the update,
Then you need the handle. Queries are placed into a subquery
DELETE fromError_barcodeWHEREBarCodeinch( SelectA.barcode from(Select * fromError_barcode) AGROUP byBarCode having Count(BarCode)>1) andId not inch ( Select min(ID) from(Select * fromError_barcode) bGROUP byBarCode having Count(BarCode)>1)
Can see I put the following two sub-queries
SELECT barCode from error_barcode GROUP by BarCode have count>1
SELECT min (ID) from error_barcode GROUPby barcode have count>1
Change into
select a.barcode from (select * from Error _barcode) a group by barcode having count (barCode) 1
Select min from (Select* from Error_barcode) b GROUPby havecount (BarCode)>1
It's all right.
MySQL Delete duplicates only keep one bar