Last answered:

16 Dec 2021

Posted on:

05 Nov 2021

1

Regarding RIGHT JOIN operation in SQL

While applying RIGHT JOIN for the tables - dept_manager_dup(left table) and departments_dup (right table), why didn't the output show up all the distinct records of the right table when the first selection was m.dept_no?
I tried reversing the names of the tables, that time I didnt notice any change in the output even after changing the first selection i.e; SELECT m.dept_no and d.dept_no produced the same results. Why does this anomaly occur?
Hoping to hear from you soon!
Thank You.

1 answers ( 0 marked as helpful)
Instructor
Posted on:

16 Dec 2021

0

Hi Meenakshi!
Thanks for reaching out.

The RIGHT JOIN keyword returns all records from the right table (table2), and the matching records from the left table (table1). The result is 0 records from the left side, if there is no match.
The SQL RIGHT JOIN returns all rows from the right table, even if there are no matches in the left table. This means that if the ON clause matches 0 (zero) records in the left table; the join will still return a row in the result, but with NULL in each column from the left table.

Hope this helps.
Best,
Tsvetelin

Submit an answer