Results 1 to 5 of 5

Thread: Update Set query?!

  1. #1
    Join Date
    Feb 2008
    Location
    Coventry
    Posts
    103
    Thanks
    5
    Thanked 8 Times in 8 Posts

    Default Update Set query?!

    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?
    The important thing is not to stop questioning. Curiosity has its own reason for existing.

  2. #2
    Join Date
    May 2007
    Location
    England, UK
    Posts
    235
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Default

    UPDATE table SET Edited='Y' WHERE ID='1' OR ID='2' OR ID = '3'

  3. #3
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    If your ID field's type is a numeric based one then you can use the following method:

    Code:
    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:

    Code:
    UPDATE your_table_name SET Edited = 'Y' WHERE ID IN ('1','2','3','4','5');

  4. #4
    Join Date
    Feb 2008
    Location
    Coventry
    Posts
    103
    Thanks
    5
    Thanked 8 Times in 8 Posts

    Default

    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.
    The important thing is not to stop questioning. Curiosity has its own reason for existing.

  5. #5
    Join Date
    Mar 2008
    Posts
    218
    Thanks
    7
    Thanked 19 Times in 19 Posts

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •