1

I want to update multiple column with multiple condition. for.eg.

update student set name='john' where id=10 
update student set name='doe' where id=5 

How to update this in a single statement?

2

2 Answers 2

4

Use CASE WHEN

update student 
set name= CASE WHEN id = 5 THEN 'john'
               WHEN id = 10 THEN 'doe'
               ELSE name 
           END
where id in (
    5, 10
)
Sign up to request clarification or add additional context in comments.

Comments

1
update tablename 
set coloumn_name1= CASE WHEN coloumn_name = 5 THEN 'john'
               WHEN coloumn_name = 10 THEN 'doe'
               ELSE name 
           END
where coloumn_name in (
    5, 10
)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.