@boomzilla said:
Ug. I use UNION ALL a fair amount, but never like this. It's usually the result of entirely separate tables, so I know there are no dupes, so there's just no point in making the DB reconfirm it.
OTOH, I see stuff where instead of a view, the coder just runs them all as separate queries. And then wonders why it takes so long. At least, I wish they'd wonder that. Since it keeps happening, I guess they probably never do.
That would be the proper way to use it. The way I always seen it used is of the form
[Some select statement]
[Some where clause]
union all
[Same select statement]
[Slightly different where clause]
union all
[repeat pattern]
What's frustrating is usually the where statements are identical except for one where blah = foo which could be combined into where blah in (foo,foo2)