Shibby Posted October 4, 2009 Share Posted October 4, 2009 Hello guys, I couldn't really remember or find anything for this. I've got a table with rows in.? Each row has an ID. ?I would like to update column 2 to be either 1 or 0 (its a bit data type) So I've got a list of IDs whose column 2 needs to be updated. What is the syntax for this again? Link to comment Share on other sites More sharing options...
0 atrotter01 Posted October 4, 2009 Share Posted October 4, 2009 This should work.... UPDATE <tablename> SET <field> = <value> WHERE id IN (id_1,id_2,id_3,id_4); Link to comment Share on other sites More sharing options...
0 00000 Posted October 4, 2009 Share Posted October 4, 2009 something along the lines of UPDATE table_name SET column_name = 1 WHERE id IN (1, 3, 6, 7, ...) should work Link to comment Share on other sites More sharing options...
0 Shibby Posted October 4, 2009 Author Share Posted October 4, 2009 cheers guys, thats what I needed. Link to comment Share on other sites More sharing options...
0 BGM Posted October 5, 2009 Share Posted October 5, 2009 just a point, if you are updating a lot of rows use a join as it is more efficient then this method.. but this is perfectly acceptable for an ad-hoc query :) Link to comment Share on other sites More sharing options...
0 Kami- Posted October 8, 2009 Share Posted October 8, 2009 Please note, it is usually better to use an EXISTS rather than an IN, there are some issues caused by using IN... :) Link to comment Share on other sites More sharing options...
Question
Shibby
Hello guys, I couldn't really remember or find anything for this.
I've got a table with rows in.?
Each row has an ID. ?I would like to update column 2 to be either 1 or 0 (its a bit data type)
So I've got a list of IDs whose column 2 needs to be updated.
What is the syntax for this again?
Link to comment
Share on other sites
5 answers to this question
Recommended Posts