Sobes.tech
Junior

What types of joins are there in SQL?

sobes.tech AI

Answer from AI

In SQL, the following types of joins exist:

  • INNER JOIN: Returns rows where there are matches in both tables. Rows without matches are discarded.

  • LEFT JOIN (or LEFT OUTER JOIN): Returns all rows from the left table and matching rows from the right table. For rows in the left table without matches in the right table, the corresponding right table fields will have NULL values.

  • RIGHT JOIN (or RIGHT OUTER JOIN): Returns all rows from the right table and matching rows from the left table. For rows in the right table without matches in the left table, the corresponding left table fields will have NULL values.

  • FULL JOIN (or FULL OUTER JOIN): Returns all rows where there is a match in the left or right table. If a row in one table has no match in the other, the corresponding fields will be NULL.

  • CROSS JOIN: Returns the Cartesian product of the rows of the two tables. Each row from the first table is joined with each row from the second table.

Example syntax:

SELECT column1, column2
FROM table1
[join_type] JOIN table2
ON table1.common_column = table2.common_column;