INNER JOIN with Examples - SQL Query
Consider the following tables.
Table1: Employee
EmpID | EmailID | Phone |
---|
1 | rajeev@gmail.com | 987654321 |
2 | sonam@gmail.com | 984454378 |
3 | anil@hotmail.com | 887899644 |
4 | keshav@yahoo.com | 789987461 |
Table2: EmpSalary
EmpCode | Salary |
---|
123 | 2000 |
456 | 25000 |
798 | 18000 |
321 | 15000 |
Table3: EmpInfo
EmpID | EmpCode | EmpFirstName | EmpLastName |
---|
1 | 123 | Rajeev | Sharma |
2 | 456 | Sonam | Gupta |
3 | 789 | Anil | Mathur |
4 | 321 | Keshav | Verma |
Q. Perform INNER JOIN to display columns Such as EmpID, EmpFirstName, EmpLastName, Salary, EmailID, Phone.
Answer:
SELECT A.EmpID, A.EmpFirstName, A.EmpLastName, B.Salary, C.EmailID, C.Phone
FROM Employee A
INNER JOIN EmpSalary B ON A.EmpCode = B.EmpCode
INNER JOIN EmpInfo C ON A.EmpID = C.EmpID
In the above query, 'A', 'B', 'C' are used as Alias.
Output:
EmpID | EmpFirstName | EmpLastName | Salary | EmailID | Phone |
---|
1 | Rajeev | Sharma | 20000 | rajeev@gmail.com | 987654321 |
2 | Sonam | Gupta | 25000 | sonam@gmail.com | 984454378 |
3 | Anil | Mathur | 18000 | anil@hotmail.com | 887899644 |
4 | Keshav | Verma | 15000 | keshav@yahoo.com | 789987461 |