Skip to content
Advertisement

SQL UPDATE SET SELECT slow [closed]

I have a SQL UPDATE, but runtime is too long. Record count more than 400000.

UPDATE items i 
SET i.itemId = (SELECT o.id FROM itemOri o WHERE i.barcode = o.barcode);

Advertisement

Answer

Make sure you have indexes on the barcode columns in both tables. Then use a JOIN instead of a subquery:

UPDATE items i
JOIN itemOri o ON i.barcode = o.barcode
SET i.itemId = o.id
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement