Can anybody tell me how to fix this query?
update ae44
set Price = Case
when ID = 'AT259793380' then '500'
when ID = 'AT271729590' then '600'
when ID = 'AT275981020' then '700'
end case
I just want to mass update listing price based on ID by matching up ID.
UPDATE ae44
SET price =
CASE
WHEN ID = 'AT259793380' THEN
'500'
WHEN ID = 'AT271729590' THEN
'600'
WHEN ID = 'AT275981020' THEN
'700'
END
Note than this query will update prices for the records with other ids to NULL.
If you only want to update only ids from your list, use this:
UPDATE ae44
JOIN (
SELECT 'AT259793380' AS oldval, '500' AS newval
UNION ALL
SELECT 'AT271729590' AS oldval, '600' AS newval
UNION ALL
SELECT 'AT275981020' AS oldval, '700' AS newval
) q
ON ae44.id = q.oldval
SET price = q.newval
UPDATE ae44 SET
Price = CASE
WHEN ID = 'AT259793380' THEN '500'
WHEN ID = 'AT271729590' THEN '600'
WHEN ID = 'AT275981020' THEN '700'
ELSE Price END
Or you can use WHERE:
UPDATE ae44 SET
Price = CASE
WHEN ID = 'AT259793380' THEN '500'
WHEN ID = 'AT271729590' THEN '600'
WHEN ID = 'AT275981020' THEN '700'
END
WHERE
ID IN ('AT259793380', 'AT271729590', 'AT275981020')
And set the LIMIT is good idea too:
UPDATE ae44 SET
Price = CASE
WHEN ID = 'AT259793380' THEN '500'
WHEN ID = 'AT271729590' THEN '600'
WHEN ID = 'AT275981020' THEN '700'
END
WHERE
ID IN ('AT259793380', 'AT271729590', 'AT275981020')
LIMIT 3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With