Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2005
»
T-SQL (SS2K5)
»
inner join returns cartesian product why?
inner join returns cartesian product why?
Rate Topic
Display Mode
Topic Options
Author
Message
Michael Tocik
Michael Tocik
Posted Monday, March 07, 2011 11:22 PM
SSCrazy
Group: General Forum Members
Last Login: Monday, April 29, 2013 2:43 PM
Points: 2,533,
Visits: 159
Hi,
I have two order tables that I am trying to join. Both have have 13 records in them but when I do an inner join on the order number I get 169 records. Both tables have a data type of varchar(7) Here is the join;
SELECT INVOICE_DETAIL_CONF_ALL.order_number
FROM INVOICE_DETAIL_CONF_ALL
inner join ORDER_EXTRACT_AUTO
on [Ord No] = ORDER_NUMBER
What am I missing?
Post #1074608
tommyh
tommyh
Posted Monday, March 07, 2011 11:54 PM
UDP Broadcaster
Group: General Forum Members
Last Login: Friday, May 10, 2013 3:15 AM
Points: 1,476,
Visits: 1,943
Michael Tocik (3/7/2011)
Hi,
I have two order tables that I am trying to join. Both have have 13 records in them but when I do an inner join on the order number I get 169 records. Both tables have a data type of varchar(7) Here is the join;
SELECT INVOICE_DETAIL_CONF_ALL.order_number
FROM INVOICE_DETAIL_CONF_ALL
inner join ORDER_EXTRACT_AUTO
on [Ord No] = ORDER_NUMBER
What am I missing?
Apart from some DDL code to see what the tables look like?
So just guessing wild:
- All the rows in both tables actually have the same Order_number
- You joining on 2 columns from the same table. Try and add the table name before the column.
/T
Post #1074610
Michael Tocik
Michael Tocik
Posted Tuesday, March 08, 2011 4:47 AM
SSCrazy
Group: General Forum Members
Last Login: Monday, April 29, 2013 2:43 PM
Points: 2,533,
Visits: 159
dope!
My mistake....I was joining on the wrong field
Post #1074690
ChrisM@Work
ChrisM@Work
Posted Tuesday, March 08, 2011 4:59 AM
SSCertifiable
Group: General Forum Members
Last Login: Today @ 8:51 AM
Points: 5,608,
Visits: 10,970
Michael Tocik (3/8/2011)
dope!
My mistake....I was joining on the wrong field
Easily done. Try to get into the habit of using table aliases:
SELECT i.order_number
FROM INVOICE_DETAIL_CONF_ALL i
INNER JOIN ORDER_EXTRACT_AUTO o
ON o.[Ord No] = i.ORDER_NUMBER
“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.”
- Gail Shaw
For fast, accurate and documented assistance in answering your questions, please read
this article
.
Understanding and using APPLY, (I)
and
(II)
Paul White
Hidden RBAR: Triangular Joins
/
The "Numbers" or "Tally" Table: What it is and how it replaces a loop
Jeff Moden
Exploring Recursive CTEs by Example
Dwain Camps
Post #1074696
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.