How to Update in 3 lines in a query

Asked

Viewed 42 times

1

How can I update to change the value of 3 lines?

I have a similar structure:

Id |             Nome                   | Ordinal
13 | Juizado Especial Cível             |    ª
14 | Juizado Especial Criminal          |    ª
15 | Juizado Especial Cível e Criminal  |    ª

I need to change the ordinal from 'ª' to 'º' of ids 13, 14 and 15 in a single query, instead of doing an update for each id.

How do I do?

Thank you very much.

  • UPDATE tabela SET campo = valor WHERE id IN (13,14,15)

2 answers

3


Simple use update with WHERE with as many conditions as necessary using relational operators in this case the OR

UPDATE table1 SET Ordinal = 'º' WHERE id = 13 OR id = 14 OR 15

Or use the IN which follows the same reasoning:

UPDATE table1 SET Ordinal = 'º' WHERE id IN (13,14,15)
  • Related: https://answall.com/q/218462/57801

  • Thank you so much! It worked, I was doing with 'and' instead of 'or' and it wasn’t working, now it was right!

  • Could you put my answer as the answer then accepts??? Thank you very much.... beware of the "and" and the "or" even confuses

2

Browser other questions tagged

You are not signed in. Login or sign up in order to post.