join

RIGHT JOIN

Preserves the right input, padding unmatched left columns. Swapping inputs and using LEFT JOIN can express the same pairing, with projection adjusted.

Formal Syntax & Structure

sql syntaxsql
a RIGHT JOIN b ON condition

Working Example

Example Snippetsql
CREATE TABLE a(id INTEGER PRIMARY KEY, k INTEGER); CREATE TABLE b(bid INTEGER PRIMARY KEY, k INTEGER); INSERT INTO a VALUES (1,10),(2,20),(3,NULL),(4,10); INSERT INTO b VALUES (101,10),(102,10),(103,30),(104,NULL);SELECT a.id,b.bid FROM a RIGHT JOIN b ON a.k=b.k ORDER BY a.id NULLS LAST,b.bid NULLS LAST;
SQL Reference