Subject Re: [firebird-support] How to compare two tables?
Author Raymond Kennington
Marco Menardi wrote:
>
> Hi, is there a "clever" sql way to compare two tables?
> Put that table A and table B have this structure:
> EMPLOYER_ID, SALARY
> I want to find:
> a) if A has EMPLOYERS (records) that B misses
> b) if B has EMPLOYERS (records) that A misses
> c) if an employer in A table has a different salary than the same has
> in B table (an vice versa, but seems not necessary to check ;))
>
> thanks!
> Marco Menardi
>

Here's something to try:

SELECT A.Employer_ID, A.Employer_ID, B.Salary, B.Salary
FROM A OUTER JOIN B
ON A.Employer_ID = B.Employer_ID
WHERE ( (A.Employer_ID = B.Employer_ID) // ***
AND (A.Salary <> B.Salary))

*** These might be the original values and not the values after the
OUTER JOIN.
If so, then use a SP and a FOR SELECT with the OUTER JOIN and
SUSPEND only the values you need using IF/THEN.

--
Raymond Kennington
Programming Solutions
TeamW2W (InfoPower)