문제

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

도움이 되었습니까?

해결책

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

다른 팁

try this:

update your_table 
set field = if(id = 1 ,'featured','non_featured')
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top