Thread: Batch Update

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2009
    Posts
    12
    Rep Power
    0

    Batch Update


    I need to Update the table A with the data from another table.

    Example

    Table A
    F1 F2
    -----------
    A 0
    B 1
    C 2
    D 3
    E 4

    Table B
    F1 F2
    ------------
    A 10
    C 20
    E 40

    Final Result will be

    Table A
    F1 F2
    -----------

    A 10
    B 1
    C 20
    D 3
    E 40

    Is there anyway do this task with a single SQL Command?

    such as
    UPDATE TableA FROM TableB

    Please Suggest. Thank in advance.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2006
    Location
    Plovdiv. Bulgaria
    Posts
    242
    Rep Power
    17
    Code:
    update a set
    f2 = (select b.f2 from b where b.f1 = a.f1) 
    where exists(select b.f1 from b where b.f1 = a.f1)

IMN logo majestic logo threadwatch logo seochat tools logo