HI.
What is the self join in sql server ? Please give any example ?
Thanks....
Self Join
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Pravin MoreRank #1,419 · 1.2K reputationPosted Nov 8, 2011, 6:45 PM EST
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.
Javeed M ShaikhRank #839 · 2.7K reputationPosted Nov 8, 2011, 2:02 PM EST
refer to this article for joins in sql server:
Introduction to Joins in Sql Server
Amit MaheshwariRank #475 · 5.2K reputationPosted Nov 14, 2011, 1:53 PM EST
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.