1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

Update table column based on another table colum

Discussion in 'SQL PL/SQL' started by jhonnyrip, Feb 16, 2019.

  1. jhonnyrip

    jhonnyrip Active Member

    Messages:
    40
    Likes Received:
    1
    Trophy Points:
    90
    Location:
    lansing
    select * from x1;

    A B
    ---------- ----------
    1 100

    select * from x2;

    A B
    ---------- ----------
    1 200

    update x1 set b=(select b from x2 where x1.a=x2.a and x1.b <>x2.b);

    1 row updated.

    select * from x1,x2;

    A B A B
    ---------- ---------- ---------- ----------
    1 200 1 200

    If I run again update , it should not update X1 table but it does.can anybody tell me why it is doing

    update x1 set b=(select b from x2 where x1.a=x2.a and x1.b <>x2.b);

    1 row updated.

    select * from x1;

    A B
    ---------- ----------
    1
    select * from x2;

    A B
    ---------- ----------
    1 200
     
    Last edited: Feb 16, 2019
  2. zargon

    zargon Community Moderator Forum Guru

    Messages:
    2,664
    Likes Received:
    375
    Trophy Points:
    1,430
    Location:
    Aurora, CO
    Is this an example, a problem, a discussion? It's confusing since there is no 'discussion' included.