How to update multiple columns in sql query


















Here is one simple command but before trying this please understand the implication of this. Without using any where command or without using any restriction the command will change all the records of the table.

So let us start with the simple command. This is not what is required in common cases so we will be changing records based on some conditions. Now we will change all the class four students to class five. We will use one where clause along with update command for updating the records.

I suspect OP just used an alias loosely because the question isn't about correctness of syntax, but "why" this syntax. Personally, I prefer using aliases throughout like I did here: stackoverflow.

Thangamani Palanisamy Thangamani Palanisamy 4, 3 3 gold badges 31 31 silver badges 38 38 bronze badges. Just to keep in mind: Although within the "inner join" t1 and t2 could be changed, "update t2" would not work. BTW: This answer is the simplest way to build your update statement beginning from a select statement that shows old and new values.

Peter Peter 1 1 gold badge 5 5 silver badges 14 14 bronze badges. This seems to work fine for my PostgreSQL Dragos Custura Dragos Custura 81 3 3 bronze badges. Then on the right of them in an independent column put the commas as designed Then you will have to copy your values into the middle column each time then just paste then and run I do not know an easier solution. Mohamed Bekheit Mohamed Bekheit 11 2 2 bronze badges.

First, get the result of table2. Next, unpivot it. Weihui Guo Weihui Guo 3, 4 4 gold badges 28 28 silver badges 49 49 bronze badges. Tushar Mellad Qarizada Mellad Qarizada 89 4 4 silver badges 16 16 bronze badges. This is pretty much just a repeat of the existing answers.

Anthony Horne 2, 2 2 gold badges 29 29 silver badges 50 50 bronze badges. Michael Kisingi Michael Kisingi 10 3 3 bronze badges. Please add some commentary to your answer to explain what it's doing. At the moment this is flagged as a low quality answer and will be deleted unless improved. The Overflow Blog. Podcast Making Agile work for data science. Stack Gives Back Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Viewed 85k times. Improve this question.

Andriy M Add a comment. Active Oldest Votes. FROM dbo. ON tgt. Improve this answer. Andriy M Andriy M Your first result for two i. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password.



0コメント

  • 1000 / 1000