Tutorials Hut

  • SQL Testing




  • SQL - Self Join With Example

    A table is joined to itself using self join .

    It is a  join between two copies of the same table.

    Syntax:
    SELECT selectList FROM table t1 JOIN table t2 WHERE condition

    Example:

    Consider Employee table having below records.

    Employee_Table1

    Match Employees who are from the same city

    SELECT e2.Employee_FirstName   AS FirstName1, e2.Employee_LastName AS LastName1, 
    e1.Employee_FirstName AS FirstName2,
    e1.Employee_LastName AS LastName2, e2.City
    FROM Employee e1 JOIN Employee e2  ON e1.EmployeeID <> e2.EmployeeID AND e1.City = e2.City
    SQL Slelf join



  • SQL Testing


















  • Leave a Reply

    Your email address will not be published. Required fields are marked *

    Scroll to Top