In terms of x compared to y.
x
SELECT *
FROM a
INNER JOIN b ON
COALESCE(b.columntojoin, b.alternatecolumn) = a.columntojoin
y
SELECT *
FROM a
INNER JOIN b ON
(case when b.columntojoin is null then b.alternatecolumn else b.columntojoin end) = a.columntojoin
COALESCE
is essentially a shorthanded CASE
statement.
Both are exactly the same.
There is also ISNULL
in SQL Server (differs in other DBMSs), but that's actually a non-standard feature and is actually more limited that COALESCE
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With