HI.
What is the self join in sql server ? Please give any example ?
Thanks....
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Pravin MorePosted Nov 8, 2011, 11:45 PM
A self-join is simply a normal SQL join that joins one table to itself. This is accomplished by using table name aliases to give each instance of the table a separate name. Joining a table to itself can be useful when you want to compare values in a column to other values in the same column. A join in which records from a table are combined with other records from the same table when there are matching values in the joined fields.
USE DatabaseName;
GO
SELECT DISTINCT tb1.ProductID, tb2.VendorID
FROM TableName tb1
INNER JOIN TableName tb2
ON tb1.ProductID = tb2.ProductID
AND tb1.VendorID = tb2.VendorID
ORDER BY tb1.ProductID
Thanks
Pravin.
Amit MaheshwariPosted Nov 14, 2011, 6:53 PM
vineet saini
http://blog.sqlauthority.com/2007/06/03/sql-server-2005-explanation-and-example-self-join/
Hope it will helpful to you if it is then accepted answer ok
thanks.
Javeed M ShaikhPosted Nov 8, 2011, 7:02 PM
refer to this article for joins in sql server:
Introduction to Joins in Sql Server