Question

In my website, I have an image table, where I store images of different products. I want to mark an Image as featured, so which will show at the front end. I give a radio button to mark it as featured. My problem is, if i already have an image as featured, and i want to update my field, how can i do the same with single query by add the new image as featured, and delete the old "featured" data.

i need something like this

update table set field=if id="1" then update to featured else update to non-featured

please help

Was it helpful?

Solution

update your_table 
set field = case when id = 1 then 'featured' 
                             else 'non_featured'
            end

OTHER TIPS

try this:

update your_table 
set field = if(id = 1 ,'featured','non_featured')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top