Results 1 to 3 of 3

Thread: update query

  1. #1
    Join Date
    Sep 2003
    Posts
    3

    Unanswered: update query

    hi

    i have 2 tables table1 with columns LOGINID and NAME. table2 has columns NAME, ADDRESS, BILL_NO, DUE_AMT. Have created a new column in table2 named LOGINID and want to insert all the values of column LOGINID of table1 into the LOGINID column of table2.

    I know i am writing an incorrect update command :
    UPDATE TABLE2 SET TABLE2.LOGINID=
    (SELECT TABLE1.LOGINID FROM TABLE1, TABLE2
    WHERE TABLE1.NAME=TABLE2.NAME)

    Now i am getting around 100 rows from the select query...how to resolve this ...i know this is simple but i donot have mcuh knowledge
    pls do respnond

    thanks

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    Seems pretty pointless and messy to duplicate data like this, but anyway...
    Code:
    UPDATE TABLE2 SET TABLE2.LOGINID=
    (SELECT TABLE1.LOGINID FROM TABLE1
    WHERE TABLE1.NAME=TABLE2.NAME)
    Of course, this requires that NAME be unique in TABLE1.

  3. #3
    Join Date
    May 2004
    Location
    Dominican Republic
    Posts
    721
    To add to Andrews' reply.. you would need to add a condition to the UPDATE statement to avoid setting NULL to those that exists on TABLE2 that doesn't on TABLE1.

Posting Permissions

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