INNER JOIN Example in SQL SERVER

INNER JOIN returns rows when there is atleast one match in both tables.This is the default JOIN in Sql Server.

Example:
Suppose if we have two tables emp and dept(for ease of understanding).

         empID   empName
             1           John
             2           Bush
             3           Scoutt
    
         deptID  empID    deptName
             1            1           IT
             2            2           Networking
             3            3           Admin

      SELECT e.empName,d.deptName FROM emp AS e
                  JOIN dept d ON e.empID = d.empID   
       
    Results:
    --------------------------
    John    IT
    Bush    Networking
    Scoutt    Admin
    --------------------------

    We can also use the where condition to get the desired output.
      
    SELECT e.empName,d.deptName FROM emp e
                  JOIN dept d ON e.empID = d.empID   
                  WHERE d.deptName = 'IT'

    Results:
    ---------------
    John    IT
    ---------------


No comments:

Post a Comment