Update mysql tables

Discussion in 'MySQL' started by Kain, Jun 23, 2009.

  1. #1
    I Have 2 tables in a mysql database

    Each one has a column holding urls called url

    table one has a boolean column

    What I want to do is search table 2 and if the same url is in both update the boolean field in table1 to 1

    any ideas on how to do this?

    Thanks
     
    Kain, Jun 23, 2009 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Something like this should work. Make sure to do a backup on your tables also.

    UPDATE my_table SET boolian_column = 1 WHERE url IN (
    SELECT url FROM other_table WHERE url = 'someurl.com'
    );

    If you remove the WHERE url = 'someurl.com' this should update every row with a corresponding url in the other table.
     
    jestep, Jun 23, 2009 IP
  3. Kain

    Kain Peon

    Messages:
    58
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for that, worked perfectly :)
     
    Kain, Jun 24, 2009 IP