Select table1.columnname, table2.columnname from table1 join table2 ON table1.columnname=table2.columnname
Example-
Table 1- emp
id | name | city | designation | departmentid | |||
---|---|---|---|---|---|---|---|
1 | ajay sharavat | noida | manager | 1 | |||
2 | Vineet Butola | noida | developer | 1 | |||
3 | sandeep kumar | noida | developer | 2 | |||
4 | Sashank Singh | delhi | admin | 2 | |||
5 | Ambrish Singh | noida | developer | 1 | |||
6 | Aamir | delhi | support | 1 | |||
7 | vishal sharavat | noida | developer | 3 | |||
8 | vinay singh | delhi | developer | 4 | |||
9 | monu | noida | support | 10 |
Table2-department
id | name | |||
---|---|---|---|---|
1 | It | |||
2 | support | |||
3 | HR | |||
4 | Sales | |||
5 | Marketing |
Join Operation
SELECT emp.name, emp.designation, department.department_name
FROM `emp` JOIN department ON emp.departmentid = department.id
Output
name | designation | department_name |
---|---|---|
ajay sharavat | manager | It |
Vineet Butola | developer | It |
Ambrish Singh | developer | It |
Aamir | support | It |
sandeep kumar | developer | support |
Sashank Singh | admin | support |
vishal sharavat | developer | HR |
vinay singh | developer | Sales |
Inner Join and Cross joins performs the same operation. Just replace JOIN to INNER JOIN or CROSS JOIN.
LEFT JOIN
No comments:
Post a Comment