SQL JOIN
$count++; if($count == 1) { include "../mobilemenu.php"; } if ($count == 2) { include "../sharemediasubfolder.php"; } ?>
An SQL JOIN is used to combine data from related tables.
Example: If you have two tables. Employee and Department, and you want to see a combined view of Employee data and Department data, you can use SQL JOINs.
Imagine that we have two tables, Employee and Department as given below.
Employee Table
FIRSTNAME
LASTNAME
AGE
DEPARTMENTID
Rambo
Robert
25
1
Mugambo
Satraj
37
1
Nagashekar
Rao
47
2
Tom
Harry
27
2
Dana
Laura
21
4
Rambo
Fox
57
4
Giselle
Chivvi
87
3
Department Table
DEPARTMENTID
DEPARTMENTNAME
1
Engineering
2
Management
3
Finance
4
Kitchen
For the above scenario, we can join the two tables using the JOIN clause.
SELECT EMPLOYEE.FIRSTNAME, EMPLOYEE.LASTNAME, DEPARTMENT.DEPARTMENTNAME
FROM EMPLOYEE, DEPARTMENT
WHERE EMPLOYEE.DEPARTMENTID = DEPARTMENT.DEPARTMENTID
Result:
FIRSTNAME
LASTNAME
DEPARTMENTNAME
Rambo
Robert
Engineering
Mugambo
Satraj
Engineering
Nagashekar
Rao
Management
Tom
Harry
Management
Dana
Laura
Kitchen
Rambo
Fox
Kitchen
Giselle
Chivvi
Finance
By doing that, we are successfully able to show the department name also in the result.