Get a Quote Right Now

Edit Template

Full Join & Cross Join

FULL JOIN: A FULL JOIN, also known as a FULL OUTER JOIN, combines the results of both the LEFT JOIN and the RIGHT JOIN. It returns all rows from both tables, along with matched rows and unmatched rows from each table. If a row doesn’t have a match in the other table, the missing columns will contain NULL values.

Syntax:

SELECT column_list
FROM table1
FULL JOIN table2
ON table1.column = table2.column;

Example From Todo Project:

SELECT
users.name,
todos.user_id
FROM
users
FULL JOIN todos
ON users.id = todos.user_id

CROSS JOIN: A CROSS JOIN, also known as a Cartesian join, combines every row from the first table with every row from the second table. It produces a result set where the number of rows is the product of the number of rows in each table.

SELECT column_list
FROM table1
CROSS JOIN table2;

Example From Todo Project:-

SELECT users.name, todos.title FROM users CROSS JOIN todos;

It’s important to note that CROSS JOINs can lead to a large number of results, especially when joining large tables. Therefore, they should be used carefully and usually in specific scenarios where you explicitly want to combine every row with every other row.

Share

Leave a Reply

Your email address will not be published. Required fields are marked *