troubleshooting Question

How to join queries

Avatar of TadSter
TadSter asked on
Microsoft SQL Server
5 Comments2 Solutions480 ViewsLast Modified:
I can't figure this out. What I have is

Folder      Client      Name      PrimarySpouse
1002      1002      John Delight      1
1002      1002      Jane Delight      0
1024      1024      Peter Sheffen      1
2056      2056      Rock Smith      1
2056      2056      Rachel Smith      0
2056      4056      Child Smith      1

What I want is 3 columns with
Client      PrimarySpouseName      SecondSpouseName

To exclude chidren I use Where L.Client = L.Folder


This join doesn't work
SELECT TOP 100 L.client
FROM [NamAddr].[dbo].[tbClients] as L
Where L.Client = L.Folder and L.PrimarySpouse = 1
Join [NamAddr].[dbo].[tbClients] as R
On L.Client = R.Client
Where R.Client = R.Folder and R.PrimarySpouse = 0
Order by Client

How do I create a join with the wife on the same record as the husband?
ASKER CERTIFIED SOLUTION
John Claes
Senior .Net Consultant & Technical Analist

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros