Sql query to update multiple values




















Agree re. I am currently engaged in so doing and in SQL Server you can now update more than 1 column per John Woo answer below. I came here to get an answer to the poster's question, not for an opinion on design — IjonTichy. Francois Beaussier 4 4 silver badges 12 12 bronze badges. Alex K. Your query is nearly correct. Field2, other columns John Woo John Woo k 63 63 gold badges silver badges bronze badges.

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. One small correction though, since in the question the name of the column is "id" it should also appear in the answer. Replace "i" with "id" everywhere. Show 2 more comments. Otherwise, I'd try with indexing on id, or modifying the architecture.

LSerni LSerni If you're really keen on doing this, you could build the query dynamically. You ought to do something like this anyway, if the values change Brian Brian 6, 6 6 gold badges 39 39 silver badges 77 77 bronze badges. I could not make Clockwork-Muse work actually. Arthur Arthur 1 1 gold badge 1 1 silver badge 10 10 bronze badges.

Ash Ash 4, 1 1 gold badge 36 36 silver badges 32 32 bronze badges. Could you please elaborate? Miguel Silva Miguel Silva 1 1 gold badge 5 5 silver badges 18 18 bronze badges. Did you actually try this? This would be great, and kinda what i am looking for.. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Stack Gives Back Safety in numbers: crowdsourcing data on nefarious IP addresses.

Spiceworks Help Desk. The help desk software for IT. Track users' IT needs, easily, and with only the features you need. Learn More ». Get answers from your peers along with millions of IT pros who visit Spiceworks. Informix Best Answer. Mark Feb 15, at UTC. I got it working!! View this "Best Answer" in the replies below ».



0コメント

  • 1000 / 1000