LXLogicExcel
๐Ÿ”ฅ
0
โญ
0
RIGHT JOIN1 / 10
RIGHT JOIN is similar to LEFT JOIN, but reversed. All rows from the second (right of JOIN) table appear in the results, and only rows from the first ("left") table with matches to the second table appear. The non-matching rows will show null. Try:

SELECT e.employee_name, c.company_name FROM companies AS c RIGHT JOIN employees AS e ON c.company_id = e.company_id;

Note which employees in the second table don't have a company_id with a match in the first table.

Also note that we are shortening the query by using table aliases to rename the tables "c" and "e."
company_idcompany_nameheadquarters
1AppleCupertino
2MicrosoftRedmond
3GoogleMountain View
4AmazonSeattle
5MetaMenlo Park
6NetflixLos Gatos
employee_idemployee_namecompany_id
1Alice Chen1
2Brian Lee3
3Carla Gomez2
4David Kim7
5Elena Rossi4
6Frank Moorenull
7Grace Patel5

Ctrl+Enter to submit

๐Ÿ”ฅ 0 streak
โญ 0 XP this lesson
All Lessons

RIGHT JOIN - Free SQL Practice Online

Practise RIGHT JOIN with 10 free, interactive SQL exercises. You type real queries into your browser and get instant feedback on every answer - no database setup, no install, and no signup. It is a fast, hands-on way to learn SQL online and build query skills you can use at work.