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

    Join Date
    Jul 2013
    Posts
    2
    Rep Power
    0

    Post Select updated rows from one table


    There are two tables like I posted below.
    I want a SQL query which selects all the rows from TABLE A which are not present in TABLE B. Also the select statement should pick all those rows which has updated value of COL_A2 in TABLE A.

    TABLE A

    COL_A1 COL_A2
    AAA MOBILE
    BBB TABLET
    CCC DESKTOP
    DDD UNKNOWN

    TABLE B

    COL_B1 COL_B2
    AAA MOBILE
    BBB UNKNOWN
    CCC DESKTOP


    The select statement should return following rows from TABLE A

    COL_A1 COL_A2
    BBB TABLET
    DDD UNKNOWN

    I am not able to write a query for this. Can anyone help me ?? It will be of great help.
    Thank You.
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,280
    Rep Power
    4279
    Code:
    SELECT tablea.col_a1 
         , tablea.col_a2 
      FROM tablea
    LEFT OUTER
      JOIN tableb
        ON tableb.col_b1 = tablea.col_a1  
     WHERE tableb.col_b1 IS NULL
        OR tableb.col_b2 <> tablea.col_a2
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    2
    Rep Power
    0
    Thank You r937

IMN logo majestic logo threadwatch logo seochat tools logo