Skip to content
Advertisement

SQL SELF JOIN return null if not exist

Recently, I got a table A like this:

I try to SELF JOIN this table by

I got this

What I expect is when VoucherID doesn’t have any reciprocal account, that record will return null, like this

Is there any elegant approach? Thanks all.

Advertisement

Answer

Why not just use aggregation?

You could also do this using left join:

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