DEV Community

Discussion on: SQL: Basics to Advanced in a Nutshell

Collapse
shivaharikumar profile image
Shiva • Edited on

can you expand on joins? the sample and explanation sounds confusing. consider the snippet from your example,
customer RIGHT OUTER JOIN payment on customer.customer_id = payment.customer_id WHERE payment.customer_id IS NULL;
why such addition in where clause? we are joining using customer_id, then why should we have IS NULL

Collapse
rksainath profile image
Sainath Ramanathan Author

In RIGHT OUTER JOIN, all rows from the right table are included, unmatched rows from the left are replaced with NULL values. So to get those unmatched data explicitly, WHERE keyword with a condition IS NULL is used. As you said you can simply eliminate the WHERE condition and see for yourself for a better understanding.