#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    2
    Rep Power
    0

    Finding non matching columns between two tables without primary key


    Hi guys...being not so good in MSsql development i need Your help in my work

    I have two tables in two different databases with same schema
    table1(label,parent,result)
    table2(label,parent,result)

    both the tables have data..but the count of both the tables are different..so my requirement is to compare data of both the tables and find out the columns which does not match and insert the same in other table.
    Note : both the table doesnt have primary key

    waiting for ur help...plz help me guys
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    117
    Rep Power
    9
    something like

    select t1.*
    from database1..table1 t1
    left join database2..tvable1 t2
    on t1.field1=t2.field1
    and t1.field2=t2.field2
    and t1.field3=t2.field3
    and t1.field4=t2.field4
    and t1.field5=t2.field5
    ...........................
    all fields from both tables
    ...........................
    where t2.field1 is null

    give you all records missing in database2
    for missing in database1 just reverse database names
    It mat runs fo long time, but you do not have indexes...
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    2
    Rep Power
    0

    It's Working


    Thanx
    ...this is exactly what i was searching for...
    Thank you very much

IMN logo majestic logo threadwatch logo seochat tools logo