May 23, 2009 at 4:23 pm
IN ARTICLE "Joins in SQL Server 2005" (http://www.c-sharpcorner.com/UploadFile/raj1979/SqlJoins10012008164642PM/SqlJoins.aspx) THE AUTHOR TALKS ABOUT USING THE NATURAL JOIN SYNTAX IN T-SQL FOR SQL SERVER 2005.
I AM UNABLE TO USE THE "NATURAL JOIN" FEATURE IN MY T-SQL CODE.
THIS FEATURE DOES NOT SEEM TO BE DOCUMENTED IN THE BOOKS ONLINE.
EXAMPLES:
SELECT *
From sys.tables t1
INNER JOIN sys.tables t2
ON t1.object_id=t2.object_id;
GO
SELECT *
From sys.tables t1
NATURAL JOIN sys.tables t2;
GO
NOTE THAT THE FIRST ONE WORKS, BUT THE SECOND ONE GIVES A SYNTAX ERROR.
May 23, 2009 at 4:30 pm
There is no NATURAL join available in SQL Server.
May 23, 2009 at 7:41 pm
The author of that article didn't do his homework on joins. There is no Natural Join in SQL Server. And, if you research it a bit, if such a thing did exist in SQL Server, it would be a very bad thing to use as most articles on natural joins in other RDBMS's suggest.
--Jeff Moden
Change is inevitable... Change for the better is not.
May 24, 2009 at 9:14 am
I think what you are looking for is an INTERSECT query. This "join" returns only the rows matching in all columns:
[font="Courier New"]DECLARE @t1 TABLE (Id INT, SomeInt INT)
DECLARE @t2 TABLE (Id INT, SomeInt INT)
INSERT INTO @t1
SELECT 1, 1
UNION ALL SELECT 2, 1
UNION ALL SELECT 3, 3
INSERT INTO @t2
SELECT 1, 1
UNION ALL SELECT 2, 2
UNION ALL SELECT 3, 3
UNION ALL SELECT 4, 1
; WITH match_all (Id, SomeInt) AS
(
SELECT * FROM @t1
INTERSECT
SELECT * FROM @t2
)
SELECT
*
FROM match_all
[/font]
May 25, 2009 at 5:44 am
I used Inner, Left , right ,
cross ,full outer joins .. But Now i am seeing this new Natural Join..
Amazing ,
Is it Available in 2008?
May 25, 2009 at 5:58 am
Hi
Nope. There is no natural join in SQL Server, even not in SSE2k8. The closed version of a natural join in an INTERSECT.
Greets
Flo
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply