2

I have a data table called Movie_Stars. I want to update multiple values, but they are all in the same column. Here's what I have:

update movie_stars
set movie_category = 'Family'
where movie_category = 'Drama'
and set movie_category = 'Children'
where movie_category = 'Cartoon'
and set movie_category = 'Teen'
where movie_category = 'Action';

But this generates the error "invalid user.table.column, table.column, or column specification". So what is the right column specification?

1 Answer 1

2

Use a CASE expression:

update movie_stars
set movie_category = case when movie_category = 'Drama'
                          then 'Family'
                          when movie_category = 'Cartoon'
                          then 'Children'
                          when movie_category = 'Action'
                          then 'Teen'
                     end
where movie_category in ('Drama', 'Cartoon', 'Action')
Sign up to request clarification or add additional context in comments.

2 Comments

sorry, but when I run you code, it says "invalid relational operator".
@Tim Sorry, I had a typo in there, please try again. Great first name, by the way!

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.