I have table in which i want to update records based on it's 'wishlist_id' value. Sample format of table records.
Expected table record after update.
So can you help to update this record using mysql query?
Assuming that all records with wishlist IS NULL
must be updated with the value taken from the closest previous (while sorting by id ASC
) record with non-NULL wishlist
value:
UPDATE test
SET wishlist = (@tmp := COALESCE(wishlist, @tmp))
WHERE (@tmp := -1)
ORDER BY id ASC
id
can be used to identify the records wherewishlist
value must be populated? does all records withname != 'wishlist'
havewishlist IS NULL
?INSERT
or restructure your tables so that they work in a normalised way and keep the relevant data in separate tables linked by the wishlist_id