Junior
What is an SQL Join and what types do you know?
sobes.tech AI
Answer from AI
Operation of concatenating strings from one or more tables based on a related column between them.
Types of SQL JOINs:
INNER JOIN: Returns rows that have matching values in both tables.LEFT JOIN(orLEFT OUTER JOIN): Returns all rows from the left table and the matched rows from the right table. If there is no match, the result is NULL on the right side.RIGHT JOIN(orRIGHT OUTER JOIN): Returns all rows from the right table and the matched rows from the left table. If there is no match, the result is NULL on the left side.FULL JOIN(orFULL OUTER JOIN): Returns all rows when there is a match in one of the tables. Combines the results ofLEFT JOINandRIGHT JOIN. If there is no match, the result is NULL in the respective side.CROSS JOIN: Returns the Cartesian product of rows from both tables (each row of the first table is combined with every row of the second table).
-- Example of INNER JOIN
SELECT *
FROM table1
INNER JOIN table2 ON table1.id = table2.table1_id;
-- Example of LEFT JOIN
SELECT *
FROM table1
LEFT JOIN table2 ON table1.id = table2.table1_id;
-- Example of RIGHT JOIN
SELECT *
FROM table1
RIGHT JOIN table2 ON table1.id = table2.table1_id;
-- Example of FULL JOIN
SELECT *
FROM table1
FULL OUTER JOIN table2 ON table1.id = table2.table1_id;
-- Example of CROSS JOIN
SELECT *
FROM table1
CROSS JOIN table2;