Sep. 24th, 2020

jbanana: Badly drawn banana (Default)
I don't know what it should really be called, but I had to do a "cross outer join" for the first time in an SQL query.
select
    coalesce(preferredValue, fallbackValue) as combined
from
    (
        select fallbackValue
        from someTable
        where someCondition
    ) a
    left join (
        select preferredValue
        from otherTable
        where otherCondition
    ) b on 1=1
This works if the second subquery returns either what you want or nothing at all. The coalesce only returns fallbackValue if the second subquery returns nothing.

The 1=1 part makes this work, but it also makes me queasy because I came across it reading about SQL injection attacks.

May 2025

M T W T F S S
   1234
5678 91011
12131415161718
19202122232425
262728293031 

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 1st, 2025 06:59 pm
Powered by Dreamwidth Studios