View Full Version : Update Set query?!
city_coder
04-08-2008, 06:38 AM
I was wondering, when it comes to updating my database, is it possible to do it like so:
UPDATE SET Edited = 'Y' WHERE ID = 1,2,3,5';
or
UPDATE SET Edited = 'Y' WHERE ID = '1' AND WHERE ID = '2' AND WHERE ID = '3'; etc etc for each number that existed?
Basically im looking to affect more than a few rows that are different to each other. Is it poossible?
jc_gmk
04-08-2008, 10:29 AM
UPDATE table SET Edited='Y' WHERE ID='1' OR ID='2' OR ID = '3'
codeexploiter
04-08-2008, 11:47 AM
If your ID field's type is a numeric based one then you can use the following method:
UPDATE your_table_name SET Edited = 'Y' WHERE ID BETWEEN 1 AND 5;
If your ID field's data type is string based one then you can try the following method:
UPDATE your_table_name SET Edited = 'Y' WHERE ID IN ('1','2','3','4','5');
city_coder
04-08-2008, 09:08 PM
Cheers guys, much appreciated for the feedback so quickly. But just to let you know i did a bit of my own research and found out how phpmyadmin did it. They just use individual update statements. so i just did that and built it myself using a for loop.
wouldnt mind a good tutorial though, at showing how to rollback to a point where the database last was. so for example when 1 bit of data was inserted but the 2nd bit that accompanied it did not go in, then i rollback the database so that the first bit of data that was inserted is taken out and the original state is resumed before the process.
hopefully iv explained that properly.
anyway if someone could tell me how or point me in the right direction of a tutorial then that would be great.
http://www.postgresql.org/docs/7.4/interactive/sql-rollback.html
http://dev.mysql.com/doc/en/commit.html
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/rollback_statement.htm
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.