Compare two Data tables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vinodksingh
    New Member
    • Jun 2010
    • 1

    #1

    Compare two Data tables

    I have following data type in one table:

    ID Company_Name
    1 ABC
    2 ABCD
    .
    .

    I n other table i have values as in following table:

    ID Company_Name Common_Name
    1 ABC Inc
    2 ABCD Ltd
    1 ABC Corp.
    2 ABCD LLc
    .
    .
    .

    What I need is to fill the "Common_Nam e in table 2 from value in table 1, and give the out put as:

    ID Company_Name Common_Name
    1 ABC Inc ABC
    2 ABCD Ltd ABCD
    1 ABC Corp. ABC
    2 ABCD LLc ABC
    .
    .
    .

    Plz help me..

    I don't have any idea of code writing.
  • MMcCarthy
    Recognized Expert MVP
    • Aug 2006
    • 14387

    #2
    OK your table structure is wrong.

    Something like this would work.

    tbl1
    ID Company_Name
    1 ABC
    2 ABCD
    .
    .

    I n other table i have values as in following table:
    tbl2 - Common_Name shouldn't be here
    ID Company_Name
    1 ABC Inc
    2 ABCD Ltd
    1 ABC Corp.
    2 ABCD LLc
    Code:
    SELECT tbl1.id, tbl2.Company_Name, tbl1.Company_Name As Common_Name
    FROM tbl1 INNER JOIN tbl2 ON tbl1.id=tbl2.id
    This will give you the output you want but I'm not sure why you have these two table in the first place. There has to be a better way to structure your data.

    Comment

    Working...