Avatar of SharonBernal
SharonBernal
 asked on

SQL Server Complex join

I have a query as follows:

select * from TBL1 inner join TBL2 where tb1.groupkey=tbl2.groupkey

I want to keep these records, however here's the problem, if groupkey is null or ZZ I need to execute the same select with a different table and where condition

select * from TBL1 inner join TBL3 where tb1.groupkey=tbl3.groupkey

Finally if this brings back duplicates I need to set groupkey to null.

I need help designing this query.
Microsoft SQL ServerMicrosoft SQL Server 2008

Avatar of undefined
Last Comment
Russell Fox

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
PortletPaul

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Russell Fox

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck