Skip to content
Advertisement

SQL – how to remove whole row if one of the column in subquery return NULL

I am stuck in 1 SQL query

This query return 4 row ( As shown in the screenshot )

I want a scenario like : If subquery return NULL , then the whole row will not be shown. So in this example “childthree” should not be shown , as “parent_user_email” is NULL , so the whole 3rd row need to remove

enter image description here

Advertisement

Answer

Use a join instead:

Note: This assumes that the email value itself is never NULL. If that is possible, add WHERE u2.user_email IS NOT NULL.

Also, your query should fail because the GROUP BY columns are inconsistent with the SELECT. However, logically it seems ok, because there is only one parent and user email per user. However, I would include those columns in the GROUP BY.

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