Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2005
    Posts
    276

    Unanswered: updating a single column

    I'm trying to update a single column into a table which has data....

    tab1
    col1 col2 col3
    aa 23 23
    cc 44 55
    dd 33 88
    Now I add a column, col4.
    col1 col2 col3 col4
    aa 23 23
    cc 44 55
    dd 33 88
    Where col1, col2 of tab1=tab2.

    I want to populate col4 from tab2.
    col1 col2 col5 col4 col6
    ..
    ..

    I used a join and an update statement but I guess I am wrong ....
    How can I do this??

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    >I used a join and an update statement but I guess I am wrong ....
    If you say so.
    >How can I do this??
    By using SQL correctly.
    What are your requirements?
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    Please paste the update command so that we can troubleshoot it. No matter how good some of our members are, we don't read minds.
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

  4. #4
    Join Date
    Jul 2005
    Posts
    276
    When i execute the following query....

    update tab1 set loc=
    (select B.loc from tab2@mylink B, tab1 A
    where B.COL1=A.COL1
    and B.COL2=A.COL2 )
    I get an error because the sub-query returns multiple rows.....perhaps I cant do it in a single statement. I'm not really sure about it though.
    Last edited by nandinir; 10-09-06 at 15:37.

  5. #5
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    You have to write it like this

    Code:
     
    update tab1  a
    set a.loc= (select B.loc from tab2@mylink B
                 where B.COL1=A.COL1
                  and B.COL2=A.COL2 ) ;
    You have to reference the row you are updating, not the entire table.
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

  6. #6
    Join Date
    Jul 2005
    Posts
    276
    Thank you so much Beilstwh, it works.

  7. #7
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    Glad to help.
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

Posting Permissions

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