Re: How to compare two tables in PostgreSQL - Mailing list pgsql-sql

From Igor Neyman
Subject Re: How to compare two tables in PostgreSQL
Date
Msg-id A76B25F2823E954C9E45E32FA49D70EC08EEEC02@mail.corp.perceptron.com
Whole thread Raw
In response to How to compare two tables in PostgreSQL  (saikiran mothe <saikiran.mothe@gmail.com>)
Responses Re: How to compare two tables in PostgreSQL  (Kamal Kumar TRR <kamalkumar.trr@gmail.com>)
List pgsql-sql
From: saikiran mothe [mailto:saikiran.mothe@gmail.com]
Sent: Saturday, November 10, 2012 10:14 PM
To: pgsql-sql@postgresql.org
Subject: How to compare two tables in PostgreSQL

Hi,

How can i compare two tables in PostgreSQL.

Thanks,
Sai


Here is simple sql to show data in table1, but not in table2:

SELECT <common_column_list> from table1
EXCEPT
SELECT <common_column_list> from table2;

And this sql shows data in table2 but not in table1:

SELECT <common_column_list> from table2
EXCEPT
SELECT <common_column_list> from table1;

Or, you could combine them in one statement, adding "indicator" column:

SELECT <common_column_list>, 'not in table2' as indicator from table1
EXCEPT
SELECT <common_column_list>, 'not in table2' as indicator from table2
UNION
SELECT <common_column_list>, 'not in table1' as indicator from table2
EXCEPT
SELECT <common_column_list>, 'not in table1' as indicator from table1;



Regards,
Igor Neyman



pgsql-sql by date:

Previous
From: Achilleas Mantzios
Date:
Subject: Re: find sudstring on text (data type) field failure
Next
From: Louis-David Mitterrand
Date:
Subject: organizing cron jobs in one function