Results 1 to 2 of 2

Thread: MySQL update query help

  1. #1
    Join Date
    Jun 2010
    Posts
    1

    MySQL update query help

    Hi,

    Assume, I have a following table whose schema is,

    create table testing (test1 integer not null, test2 integer not null, test3 integer not null, test4 integer not null);

    And assume the following details are inserted:

    insert into testing values (1,1,0,0);insert into testing values (1,1,1,0);insert into testing values (1,1,2,0);insert into testing values (1,2,0,0);insert into testing values (1,2,1,0);insert into testing values (1,2,2,0);insert into testing values (1,2,3,0);insert into testing values (1,3,0,0);insert into testing values (1,4,0,0);insert into testing values (1,4,1,0);

    mysql> select * from testing;
    +-------+-------+-------+-------+
    | test1 | test2 | test3 | test4 |
    +-------+-------+-------+-------+
    | 1 | 1 | 0 | 0 |
    | 1 | 1 | 1 | 0 |
    | 1 | 1 | 2 | 0 |
    | 1 | 2 | 0 | 0 |
    | 1 | 2 | 1 | 0 |
    | 1 | 2 | 2 | 0 |
    | 1 | 2 | 3 | 0 |
    | 1 | 3 | 0 | 0 |
    | 1 | 4 | 0 | 0 |
    | 1 | 4 | 1 | 0 |
    +-------+-------+-------+-------+
    10 rows in set (0.00 sec)

    Here, I want to update the column test4 as 1 for the following scenario with a single update query.

    1. where test1=1 and test2=1 and test3=2
    2. where test1=1 and test2=2 and test3=3
    3. where test1=1 and test2=3 and test3=0
    4. where test1=1 and test2=4 and test3=1

    ie, need to update which has maximum value in test3 column and also group by test1 and test2..

    Is there a way to update it in a single update Query..

    Thanks in Advance.

    Regards,

  2. #2
    Join Date
    Feb 2011
    Posts
    6
    If I understood correctly - you would like to set col4 to 1 when ANY of the 4 conditions are met?

    Bert

Posting Permissions

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