Forum Moderators: coopster

Message Too Old, No Replies

Updating Multiple rows

         

bodycount

1:49 pm on Mar 12, 2007 (gmt 0)

10+ Year Member



Hi I need help I am trying to update multiple rows in my db. I select the following from the db and I want to update id 5 , 60 , 2500 ,8630 using checkbox's to select the ones i want to update, and i want to update the following fields. company, advice note and shipdate.

id ¦¦serialno¦¦company¦¦advice_note¦¦shipdate
5 ¦¦123456¦¦STOCK ¦¦ ¦¦0000-00-00
25 ¦¦123457¦¦STOCK ¦¦ ¦¦0000-00-00
60 ¦¦555666¦¦STOCK ¦¦ ¦¦0000-00-00
2500 ¦¦458996¦¦STOCK ¦¦ ¦¦0000-00-00
5800 ¦¦999991¦¦STOCK ¦¦ ¦¦0000-00-00
5959 ¦¦999956¦¦STOCK ¦¦ ¦¦0000-00-00
6589 ¦¦458964¦¦STOCK ¦¦ ¦¦0000-00-00
8630 ¦¦126548¦¦STOCK ¦¦ ¦¦0000-00-00
10600¦¦188925¦¦STOCK ¦¦ ¦¦0000-00-00

I can update a single line no problem but mutiple lines I just dont know where to start.

Sekka

2:35 pm on Mar 12, 2007 (gmt 0)

10+ Year Member



Run multiple queries. Easiest way when you are not too concerned about server load.

joelgreen

5:50 pm on Mar 12, 2007 (gmt 0)

10+ Year Member



If you want update different rows with different values then you'll have to execute separate query for each row.

If you want to update all those rows with the same data then here is sql statement:

update TABLENAME
set company = "some value", advice_note = "some value", shipdate = "some value"
where id = 5 or id = 60 or id = 2500 or id = 8630

Note: such "compound" update statement is not recommended because it would not use index => thus slowness on large tables.

Bottom line: in either case you would better run separate query for each row :-)