JOIN
clause is used to combine rows from two or more tables, based on a related column between them.
Here is the sample of Engineer table
id | fullname | title | department | manager |
---|---|---|---|---|
1 | Eric Brown | Software Engineer | IT | Frank Martin |
2 | Brandon Hart | DevOps Engineer | IT | Justin Martin |
3 | Connor Langdon | Software Engineer | IT | Lucas Scott |
Here is the sample of Certificate table
id | engineerid | certificatename | certificatedate |
---|---|---|---|
1 | 1 | Docker Certified Associate | 2020-05-05 |
2 | 2 | Certified Kubernetes Administrator | 2021-07-03 |
Examples / Outputs
1SELECT e.id, e.fullname, c.certificatename
2FROM engineer AS e
3INNER JOIN certificate AS c
4ON e.Id=c.Engineerid;
engineerid | fullname | certificateName |
---|---|---|
1 | Eric Brown | Docker Certified Associate |
2 | Brandon Hart | Certified Kubernetes Administrator |
Different Types of SQL JOINs
INNER JOIN : Returns records that have matching values in both tables
LEFT (OUTER) JOIN : Returns all records from the left table, and the matched records from the right table
RIGHT (OUTER) JOIN : Returns all records from the right table, and the matched records from the left table
FULL (OUTER) JOIN : Returns all records when there is a match in either left or right table