The nested select statement is frequently misused, in particular if you get no rows back from the expression that's an error. So for instance:
This will throw (with a peculiar error,
SQLITE_DONE) if there is no such row.
Sometimes people try to fix this problem with a nullcheck:
That doesn't help at all. It's not a null value situation, there's no row at all.
Is likewise unhelpful. To help with this situation we add two forms:
Both of these deal with the case where there is no row. The second lets you have a simple default for both no row or null value. That form is equivalent to:
i.e. both problem cases are handled.
Of course the -1 here could be any valid expression, even a second