Results 1 to 6 of 6
  1. #1
    Join Date
    May 2004
    Posts
    4

    Thumbs up Unanswered: Extracting data from 2 tables.....

    Cheers

    I would really apprecite if anyone could make a comment on this...

    what i wanna know is....
    there are two tables, called 'A' and 'B' with identical structures...
    is it possible to Perform the following in a single SQL ....

    * If A->Field1 = B->Field1 then A->Field2 + b->Field2
    * Records of table 'A' which not in table 'B' and
    * Records of table 'B' which not in table 'A'

    Thanks
    Last edited by Sajan; 05-19-04 at 05:03.

  2. #2
    Join Date
    May 2004
    Posts
    4
    Hi man!
    UPDATE A
    SET A.Field2=A.Field2+b
    FROM A inner Join B On A.Filed1=B.Filed1

    Good Luck!

  3. #3
    Join Date
    May 2004
    Posts
    4

    Thumbs up Thanks a lot ...

    Cheers Jekker

    Thanks a lot for your effort....
    the code which u posted could be useful and will perform,

    * If Records in table 'A'->field1 = table 'B'->field1 then
    'A'->field2 + 'B'->field2

    * Records in table 'A' but not in table 'B' (Unique to 'A')

    # But records in table 'B' which isnt in table 'A' wont get inserted to the table 'A' !

    What i need is just a SQL to extract data and not to update...

    anyway thanks again for your effort and for your time.

    take care
    Last edited by Sajan; 05-19-04 at 06:55.

  4. #4
    Join Date
    May 2004
    Posts
    4
    Sorry I was wrong.
    I try again!

    * If A->Field1 = B->Field1 then A->Field2 + b->Field2
    SELECT (A.Field2+b) as NewField
    FROM A Inner Join B ON A.Field1=B.Field1

    * Records of table 'A' which not in table 'B' and
    SELECT A.* FROM
    A LEFT JOIN B ON A.Field1=B.Field1
    WHERE B.Field1 Is Null

    * Records of table 'B' which not in table 'A'
    SELECT B.* FROM
    A Right Join B ON A.Field1=B.Field1
    WHERE A.Field1 Is Null

    Check it

  5. #5
    Join Date
    May 2004
    Posts
    4

    Red face Hey Jekker

    Is it Possible to COMBINE the 3 SQLs which you have posted?
    what i need is to merge it into one SQL

    Thanks

  6. #6
    Join Date
    May 2004
    Posts
    4
    mmm
    You can use Union.

    SELECT (A.Field2+b) as NewField
    FROM A Inner Join B ON A.Field1=B.Field1
    UNION
    --Records of table 'A' which not in table 'B' and
    SELECT A.Field1 as NewField FROM
    A LEFT JOIN B ON A.Field1=B.Field1
    WHERE B.Field1 Is Null
    UNION
    -- Records of table 'B' which not in table 'A'
    SELECT B.Field1 as NewField FROM
    A Right Join B ON A.Field1=B.Field1
    WHERE A.Field1 Is Null

    But you should know, that UNION work like DISTINCT.

Posting Permissions

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