Joins

SQL Joins is used to combine data or rows from two or more tables based on a common field between them. Different types of Joins are:

Employee Table

idnamecity
1AshishPune
2patelNagpur
4AnsuBikaner

Age Table

idage
123
227
321

Inner Join

It selects all rows from both the tables as long as the condition satisfies. Only using JOIN is same as INNER JOIN

SELECT
  employee_age.id,
  employee.name,
  employee.city
FROM employee
INNER JOIN employee_age
  ON employee.id = employee_age.id;
idnamecityage
1AshishPune23
2patelNagpur27

Left Join

This join returns all the rows of the table on the left side of the join and matching rows for the table on the right side of join.

SELECT
  employee_age.id,
  employee.name,
  employee.city
FROM employee
LEFT JOIN employee_age
  ON employee.id = employee_age.id;
idnamecityage
1AshishPune23
2patelNagpur27
NULLAnsuBikanerNULL

Right Join

RIGHT JOIN is similar to LEFT JOIN. This join returns all the rows of the table on the right side of the join and matching rows for the table on the left side of join.

SELECT
  employee_age.id,
  employee.name,
  employee.city
FROM employee
RIGHT JOIN employee_age
  ON employee.id = employee_age.id;
idnamecityage
1AshishPune23
2patelNagpur27
3NULLNULL21

Full Join

FULL JOIN creates the result-set by combining result of both LEFT JOIN and RIGHT JOIN.

SELECT
  employee_age.id,
  employee.name,
  employee.city,
  employee_age.age
FROM employee
FULL JOIN employee_age
  ON employee.id = employee_age.id;
idnamecityage
1AshishPune23
2patelNagpur27
3NULLNULL21
NULLAnsuBikanerNULL
.scroll-to-top {
font-size: 2.5rem;
width: 3.2rem;
height: 3.2rem;
display: none;
align-items: center;
justify-content: center;
position: fixed;
padding: 0.75rem;
bottom: 4rem;
right: calc(1.25rem + 90px + var(--page-padding));
z-index: 999;
cursor: pointer;
border: none;
color: var(--bg);
background: var(--fg);
border-radius: 50%;
}
.scroll-to-top.hidden {
display: none;
}
.scroll-to-top i {
transform: translateY(-2px);
}
@media (min-width: 1080px) {
.scroll-to-top {
display: flex;
}
}