May 23, 2005 at 1:54 pm
I have tried looking this up on BOL as well as this site and Google. I must be asking the wrong question - that is the important thing in life, isn't it?
I cannot seem to generate different results when I use INNER JOIN versus JOIN. Is INNER an artifact the older OUTER JOIN terminology? Has someone run into an instance where different results were achieved using JOIN rather than INNER JOIN?
Thanks.
I wasn't born stupid - I had to study.
May 23, 2005 at 2:05 pm
INNER JOIN is the explicit version of JOIN. By DEFAULT if no join type is given SQL says INNER JOIN...
Good Hunting!
AJ Ahrens
webmaster@kritter.net
May 23, 2005 at 2:10 pm
Thanks. I figured that, but I could find no documentation.
I wasn't born stupid - I had to study.
May 23, 2005 at 2:51 pm
Farrell,
AJ already mentioned that INNER JOIN is the default JOIN type. Try this
USE PUBS
SELECT
r.royalty
, t.title
, t.type
, t.price
FROM
roysched r
INNER JOIN
titles t
ON
r.title_id = t.title_id
ORDER BY
r.royalty
SELECT
r.royalty
, t.title
, t.type
, t.price
FROM
roysched r
JOIN
titles t
ON
r.title_id = t.title_id
ORDER BY
r.royalty
SELECT
r.royalty
, t.title
, t.type
, t.price
FROM
roysched r
MERGE JOIN
titles t
ON
r.title_id = t.title_id
ORDER BY
r.royalty
and you'll see, why it is preferrable to be explicite in the JOIN type you want to use. I think I've also read this in BOL, but can't remember where right now.
...If you ask me, I think it's one of those little SQL Server annoyances.
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
May 23, 2005 at 3:06 pm
From Books online (From Clause):
< join_type >
Specifies the type of join operation.
May 23, 2005 at 3:17 pm
Thanks Ron. I had seen that, but it just wasn't specific enough for me as to whether it would make a difference in the results.
---------------------------------------------------------------------------------
Frank, I had to use different tables.
I get an error using MERGE JOIN. Can you see what I have done wrong?
SELECT S.STATE_CODE, P.STATE_CODE, P.EMAIL_ADDR, PERSON_ID
FROM PERSON_ADDRESSES P
MERGE JOIN STATES S ON( P.STATE_CODE = S.STATE_CODE)
ORDER BY P.EMAIL_ADDR -- x records
I wasn't born stupid - I had to study.
May 23, 2005 at 6:35 pm
Merge Join is a Join HINT not a join type.
From books online:
This example performs a three-table join among the authors, titleauthors,
and titles tables to produce a list of authors and the books they have written.
The query optimizer joins authors and titleauthors (A x TA) using a MERGE join.
Next, the results of the authors and titleauthors MERGE join (A x TA) are
HASH joined with the titles table to produce (A x TA) x T.
Important After a join hint is specified, the INNER keyword is no longer optional and
must be explicitly stated for an INNER JOIN to be performed.
USE pubs
SELECT SUBSTRING((RTRIM(a.au_fname)
+ ' ' + LTRIM(a.au_lname)), 1, 25) AS Name,
SUBSTRING(t.title, 1, 20) AS Title
FROM authors a INNER MERGE JOIN titleauthor ta
ON a.au_id = ta.au_id INNER HASH JOIN titles t
ON t.title_id = ta.title_id
ORDER BY au_lname ASC, au_fname ASC
May 24, 2005 at 12:50 am
Farrell, you did nothing wrong. That's exactly what I meant with little annoaynce. Not that one should specify JOINs hints as normal way of doing business, but when you specify a JOIN hint, you also need to write INNER. Obviously SQL Server "forgets" about INNER JOIN being the default in such cases.
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
May 24, 2005 at 7:38 am
Thank you guys! I was born with an extra thick skull, so it usually takes two or three hammers to get me to understand.
I wasn't born stupid - I had to study.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply