Joining on the Presence of NULL Values in SQL

Tiempo de lectura: < 1 minuto

In SQL, joins are used to combine rows from two or more tables based on a related condition between them. I will show you how to use the most important joins: INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN, with NULL checks to handle unmatched rows.

INNER JOIN returns only the rows that have a match in both tables. No NULL check is needed, as it only returns rows that match in both tables.

Syntax:

LEFT JOIN returns all rows from the left table and the matching rows from the right table. If there are no matches, it returns NULL in the columns from the right table.

Syntax:

NULL Check:

RIGHT JOIN returns all rows from the right table and the matching rows from the left table. If there are no matches, it returns NULL in the columns from the left table.

Syntax:

(NULL Check):

FULL JOIN returns all rows when there is a match in one of the tables. If there are no matches, it returns NULL in the columns from the table that does not have matches.

Leave a Comment