• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Bizarre SQL Union/All Result

Eluros

Member
Greetings,

So, for work, I have two queries, A and B. When run by itself, A returns 1 row (with 1 varchar column) and B returns 1984 rows (with 1 varchar column). Neither A nor B, by themselves, return any null results.

However, when I run the following:

A
UNION ALL
B

17 of the resulting 1985 rows are null. Union returns 1963 (of the expected 1985) rows, 22 of which are presumably consolidated into the single "null" that shouldn't exist.

I find it bizarre that Union and Union All return null rows when the queries that compose them don't return any null rows. Further, I find it odd that the number of null rows varies!

Any ideas what can cause this, oh ye SQL gods?

As always, much obliged for your help.
 
So, I was able to figure out the core problem: I was concatenating a series of values, one of which could have potentially been null. As I should have prepared for, value + null == null.

I added a coalesce to replace any null values with empty strings and everything works as it should. Should have thought of that from the get-go.
 
Back
Top