Compare column rows in two tables

  • Hi

    I would like to compare rows which are in two different tables which have the same column and data type where the data in one table1 column (A) has repeated data. When new data is added to table1 column (A) the unique rows should be selected and added to another table2 column (A) on the same database.

    Both tables have the same column name but the rows in table1 column (A) are repeated while the rows in table2 column (A) are unique.

    Data is always added to table1 columnA everyday. How do i selected only the unique rows in table1 column (A) and add it to table 2 (A). To give an idea there are about 50,000 rows in table1 column (A) and about 1000 rows in table 2 column(A)

    Any help is much appreciated. New to SQL so please give in detail.

    Thanks.

  • use a distinct on the select from table A:

    Select Distinct col1, col2, col3

    from tableA

    add a clause if you want to exclude everytihng from tableB

    Select Distinct a.col1, a.col2, a.col3

    from TableA a

    left outer Join TableB b

    on a.col1 = b.col1

    where b.col1 is null

  • Please will you post your table structures in the form of CREATE TABLE statements and also give some sample data in the form of INSERT statements. Also, please show what you would expect to happen when further sample data is added. It's difficult to know what you mean by duplicate data - is it where the whole row is the same, or just the primary key?

    John

  • here's a good article on how to post:

    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    as you're new to SQL, have a look at my first reply if any confuses you then you need to get an SQL book and look those terms up

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply