RE: [SQL] comparing 2 tables. . . - Mailing list pgsql-sql

From Daniel Péder
Subject RE: [SQL] comparing 2 tables. . .
Date
Msg-id 01BF06A4.7FFF3C60@Dan
Whole thread Raw
Responses RE: [SQL] comparing 2 tables. . .
List pgsql-sql
try this, it should select what in tab1 is not in tab2 ( compared by pkeys )

select pkey.tab1 where pkey.tab1 not in ( pkey.tab2 );

--

dan peder
dpeder@infoset.cz
http://shop.culture.cz

-----Original Message-----
From:    JT Kirkpatrick [SMTP:jt-kirkpatrick@mpsllc.com]

can anyone help please??

we have two tables in our database that *should* have the exact same number 
of records, with identical values in their corresponding primary keys (pk 
same in both tables, int4).  for this example, table t1 with primary key 
pk, and table t2 with primary key pk.  after about 3 months of use and a 
crash last night i see that the two tables do NOT have the same number of 
records -- one is missing some that it should have.  is there a way i can 
compare the two tables and select ONLY the records that do NOT exist in the 
2nd table??  if i could identify the records (and the pk) then i could 
manually insert them.  each table has over 50,000 records so it is not 
feasable to review each record to find them manually (which i tried last 
night. . .).

we are struggling this morning -- any help you could provide quickly would 
be greatly appreciated!

jt kirkpatrick / mps

************



pgsql-sql by date:

Previous
From: JT Kirkpatrick
Date:
Subject: comparing 2 tables. . .
Next
From: Daniel Péder
Date:
Subject: RE: [SQL] comparing 2 tables. . .