Skip to content
Advertisement

SQL query returning 0 rows after adding extra INNER JOIN

The issue is simple to explain, but seemingly not so simple to solve.

This SQL query returns 0 rows:

This one, however, returns 1 row as I expected:

The only difference is the lack of INNER JOIN with the org_depts table.

What I want to be returned is all the column values from app_handover, which references sys_logins.id in its sent_by column. I also want the value of org_depts.dept_name, which is referenced by sys_logins.dept_id.

I cannot think of an alternative syntax to use, but clearly there is an error in my logic in the first example, which is returning 0 rows instead of 1 as I expected.

Advertisement

Answer

Yep, LEFT JOIN was the answer. The value of dept_id in the matching sys_logins row was NULL, so no matching record was found in org_depts.

This query works and now returns 1 row:

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