Skip to content
Advertisement

Using NVL with JOIN

I want to display 2 values in table but only Student 301 is displayed. Student 102 doesn’t received any grades. I joined two tables. Here’s my query. Thanks for your help

Advertisement

Answer

Presumably, both students are in enrollment_info. If so, you can use:

Note the use of LEFT JOIN. The table where you want to keep all the rows comes first. You can filter on this table in the WHERE clause. Although not part of this question, filters on subsequent tables (when using LEFT JOIN) should be in the ON clause.

Also note the use of meaningful table aliases rather than arbitrary letters. Arbitrary letters make the query much harder to follow — and make it easy to make mistakes.

If both students are not in enrollment info, then you need to start with them using a derived table of some sort. That would look like:

This also uses COALESCE() instead of NVL() because COALESCE() is the Standard SQL function for replacing NULL values.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement