Link to home
Start Free TrialLog in
Avatar of brgdotnet
brgdotnetFlag for United States of America

asked on

help with tricky query.

I need to compare Table_1 and Table_2.

Table_1 and Table_2 both have duplicate records. Table_2 has more duplicate records in it than table_1.
I need a list of all of the names in table_2 that are also in table_1. But I want the names of those in Table_2
that have more duplicate names in table_2. So for example, below both tables have Joseph Dreadson in them.


Table_2 has more records in it than Table_1.

I need a list of all of the names in Table_2 that have more records than their matching names in
Table_1.


So for these two tables :


Table_1
FNAME   LNAME
Bob     Candoiti
Mary    Semper
Mary    Semper
Mary    Semper
Joseph  Dreadson
Terry   James




Table_2
FNAME   LNAME
Bob     Candoiti
Mary    Semper
Mary    Semper
Joseph  Dreadson
Joseph  Dreadson
Joseph  Dreadson
Terry   James
Terry   James



So the desired query would return these two records, because these people occur more frequently in table_2 than table_1
 :

Joseph Deadson
Terry  James
ASKER CERTIFIED SOLUTION
Avatar of PortletPaul
PortletPaul
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of brgdotnet

ASKER

Awesome!
WHERE T2.count_t2 > T1.count_t1
OR T1.count_t1 IS NULL
OR T2.count_t1 IS NULL

it may need to cater for NULLs which I forgot