SQL joining to a table from two other tables in one go

Posted on 2014-01-08
Last Modified: 2014-01-08
Hi all,

I have inherited this query from a colleague.  I am not sure whether it is OK / recommended / downright wrong to join to a third table using fields from two other tables in the one join.

Can you advise please?

Question by:colinspurs
LVL 48

Accepted Solution

PortletPaul earned 500 total points
ID: 39764718
It is quite acceptable to join like that.

Hard to give more advice without knowing more about the data & relationships; but is not "wrong"

Author Comment

ID: 39764785
Ok thanks.  I don't see that too often and suspect I have duplicate rows so wanted to verify it.

LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39764790
I concur that this is perfectly possible (I use i almost every day).

if you have "duplicate rows", you may want to read up this article for explanations and solutions:
LVL 13

Expert Comment

ID: 39764803
Yes, duplicates could be due to "cartesian product" or incorrect logic.
LVL 48

Expert Comment

ID: 39764979
Thanks for the points...

"duplicate rows" usually means "unexpected, and unwanted, repetition" that may not be due to that join. Most often it is many-to-one relationships that are the cause.

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sql server Transfering records getting error #NAME? 6 39
tempdb latch contention 12 47
Make query more efficient 1 16
SQL Query Syntax Join 4 27
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now