Junior — Middle
What is the purpose of the RIGHT JOIN operator in SQL?.
sobes.tech AI
Answer from AI
The RIGHT JOIN operator in SQL is used to combine two tables so that the resulting set includes all rows from the right table and the matching rows from the left table. If there is no match for a row from the right table in the left table, the fields from the left table will be filled with NULL.
Example:
SELECT A.id, B.name
FROM A
RIGHT JOIN B ON A.id = B.a_id;
This query will display all records from table B, and only those from table A that meet the join condition. This is useful when you want to keep all data from the right table, even if there is no related information in the left table.