Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to use Right Join on two tables

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 423
    Comment on it

    Right Join:

    Right Join is used to join two tables and it return all rows from right table(table 2) and matching rows from table 1(left table). The result is NULL for unmatched rows for table 1(left table). Right Join keyword is used to apply Right Join on two tables.

    Syntax for Right Join:

    SELECT columnname(s)
    FROM tablename1
    RIGHT JOIN tablename2
    ON tablename1.columnname=tablename2.columnname;
    

    In the above syntax there is a column taken from both table on which Right join is applied and this column must be same in both tables.

    Example of Right Join:

    Employee Table:

     EmpID          EmpName              City  
    -----------------------------------------
      1             Akhil            Haridwar 
      2             Shilpi           Dehradun   
      3             Neha             Selaqui      
      4             Rohit            Rajpur   
      5             Harshit          Rishikesh    
    

    Department Table:

     EmpID          Department            Salary  
        -----------------------------------------
         1               PHP                 15000
         2               HTML                10000
         3               PHP                 15000
         4               ActionScript        18000    
    

    As we have two tables Employee table and department table and we are applying Right join on it using EmpID column.

     SELECT  EmpID, EmpName, Department, Salary
     FROM EMPLOYEE
     RIGHT JOIN Department
     ON EMPLOYEE.EmpID = Department.EmpID;
    

    Output for the above query will be like this:

     EmpID           EmpName            Department            Salary  
    ----------------------------------------------------------------------------
       1               Akhil               PHP                 15000
       2               Shilpi              HTML                10000
       3               Neha                PHP                 15000
       4               Rohit               ActionScript        18000 
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: