Is it possible to change more than one record at a time?

Asked

Viewed 121 times

7

That is the code:

UPDATE PESSOAS
SET COR = ('Pardo')
WHERE ID = 1;

But I have 2 more records to do the same procedure, I could do everything at once adding the ID?

  • Ramon, what kind of data that column stores. You could share the information in the structure of this table, for a better understanding of your question

  • it is sufficient that the other records enter the condition of the WHERE as Maniero posted

  • Caique follows the structure: CREATE TABLE PEOPLE ( ID INT NOT NULL AUTO_INCREMENT, VARCHAR NAME (30) NOT NULL, NASCIMENTO DATE, SEX CHAR (1), VARCHAR PROFESSION (15), DECIMAL WEIGHT (5,2), DECIMAL HEIGHT(3,2), NATIONALITY VARCHAR (10) DEFAULT 'Brasil', PRIMARY KEY (ID) ); Ai I used ALTER TABLE + ADD COLUMN to add a new column, "COLOR". With this, I would like to fill out this field that is empty in all the records at once.

1 answer

14


Suffice it to say in the clause WHERE you wish to do in several, could use a OR to select several IDbut I think in this case it is more appropriate to use the IN().

UPDATE PESSOAS
SET COR = ('Pardo')
WHERE ID IN (1, 2, 3);

I put in the Github for future reference.

  • That would be it, but I tried it this way that you passed but did not change, the message that returned was the following: 16:03:34 UPDATE PEOPLE SET COLOR = ('Brown') WHERE ID = (1,2,3) Error Code: 1241. Operand should contain 1 column(s) 0,000 sec

  • @Ramonalmeida You changed the = for IN? See in Maniero’s code that the secret is precisely the IN.

  • I didn’t pay attention to the detail, it worked here!! Thanks guys, really, really helped a lot!!

Browser other questions tagged

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