Sql 2005 Query - Inner\Outter Join issue

I am getting triple record from this query.  I think things are being joined incorrectly.  Can someone shed some light on this for me?  I believe I need to use Inner and Outter joins but the concept is new to me.

Thanks

Select F.ORDERNUM, A.Customer_ID, A.CUSTOMER_PO_REF,A.SHIPTO_ID,
B.INVOICE_ID, B.INVOICED_DATE,
C.UNIT_PRICE, C.SHIPPED_QTY,
D.PART_ID, D.MISC_REFERENCE, D.TOTAL_AMT_ORDERED,
E.VEHICLE_ID, E.WAYBILL_NUMBER, E.CARRIER_ID,
F.TRACKNUM
FROM CUSTOMER_ORDER A, SHIPPER B, SHIPPER_LINE C, CUST_ORDER_LINE D, UV_BOL_INVOICE2 E, ISS_ORDERCASE F
WHERE F.ORDERNUM = A.ID AND
F.ORDERNUM = B.CUST_ORDER_ID AND
F.ORDERNUM = C.CUST_ORDER_ID AND
F.ORDERNUM = D.CUST_ORDER_ID AND
F.ORDERNUM = E.CUST_ORDER_ID
LVL 3
JluchtAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve WalesSenior Database AdministratorCommented:
Without knowing the exact layout of your tables, it's a little hard to troubleshoot for you.

However, the construct you've used is always going to be an inner join.

Inner Joins are going to return only those rows that exist in both tables involved in the join.

An outer join can return those rows that exist in one and don't have matches in the other table.

In order to use an outer join, you are going to want to use ANSI standard syntax:

select col1, col2, col3
from table 1 a
[LEFT|RIGHT|FULL] [INNER|OUTER] join table 2 b on a.col1 = b.col1

So you can do (INNER):

table1 a
JOIN table2 b on a.col1 = b.col2

or LEFT OUTER:

table1 a
LEFT JOIN table2 b on a.col1 = b.col2

For your example if SHIPPER_LINE and CUST_ORDER_LINE have multiple rows per line in SHIPPER and CUSTOMER_ORDER then multiple lines per order is highly likely.

Does that help ?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Brian CroweDatabase AdministratorCommented:
I don't really have much more than what Steve said towards answering your question but I would like to emphasize...

Please, for the love of god and any developer that has to come behind you don't use comma-delimited join syntax in your queries.  It is non-standard, antiquated, prone to error, and just plain hard to read.  Also I would recommend choosing table aliases that are more significant to your tables.  Instead of using sequential alphabetical characters use "O" or "CO" for Customer_Order, "S" for Shipper or whatever as long as it is a little more intuitive when looking at the SELECT clause.  The best way I know of to trouble-shoot a query like this is to add a table at a time (another thing you can't easily do with your syntax) and watch the row counts.

Select COUNT(*)
FROM CUSTOMER_ORDER AS A
INNER JOIN SHIPPER AS B
	ON CUST_ORDER_ID = B.CUST_ORDER_ID
INNER JOIN SHIPPER_LINE AS C
	ON A.CUST_ORDER_ID = C.CUST_ORDER_ID
INNER JOIN CUST_ORDER_LINE AS D
	ON A.CUST_ORDER_ID = D.CUST_ORDER_ID
INNER JOIN UV_BOL_INVOICE2 AS E
	ON A.CUST_ORDER_ID = E.CUST_ORDER_ID
INNER JOIN ISS_ORDERCASE AS F
	ON A.CUST_ORDER_ID = F.ORDERNUM

Open in new window

PortletPaulEE Topic AdvisorCommented:
This is what Brian (and I) do NOT want you to do:

FROM CUSTOMER_ORDER A, SHIPPER B, SHIPPER_LINE C, CUST_ORDER_LINE D, UV_BOL_INVOICE2 E, ISS_ORDERCASE F

Yuk!

No points please (not that its likely for this one)
PortletPaulEE Topic AdvisorCommented:
Jlucht, do you still need help on this question?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.