Reputation: 45
i have two columns in my database table. i want to update both the columns in a single query but with two different conditions for each column. how to achieve this..?? Please Help.
Thanks in Advance.
I am using mysql database.
Upvotes: 0
Views: 822
Reputation: 204746
UPDATE import
SET customer_name = case when customer_name = ''
then 'N/A'
else customer_name
end,
city = case when city = ''
then 'N/A'
else city
end
Upvotes: 6
Reputation: 28763
Try like
UPDATE import SET
customer_name
CASE
WHEN customer_name= ''
THEN 'N/A'
ELSE custore_name
END,
city
CASE
WHEN city=''
THEN 'N/A'
ELSE city
END
Upvotes: 1
Reputation: 7433
It's not really clear, what you want to do, but how about:
update ...... set column1 = if(condition_column1 = 1, 'some_value', column1), column2 = if(condition_column2 = 2, 'other_value', column2)
this will work the same way as:
update ...... set column1 = 'some_value' where condition_column1 = 1
update ...... set column2 = 'other_value' where condition_column2 = 2
Upvotes: 0