Union All problem

Database

Union All problem

Can anyone explain the following odd results?

When I execute the following query:

select 'x' ,count(*) from dbc.databases
union all
select 'x1' ,count(*) from dbc.databases

I get the following results:

x 193
x 193

but when I run it this way:

select 'x1' ,count(*) from dbc.databases
union all
select 'x' ,count(*) from dbc.databases

I get the following results:

x1 193
x 193

I don't understand why the literal is change in the first example. This seems to only occur when the literal from the first is contained in the second literal. It also has interesting results with '1x', '3xa','bfgfxj234'....
2 REPLIES
N/A

Re: Union All problem

Instead of changing the select sequence, you can also cast the first literal with max character you need. This will provied the complete result set and literal will not be truncated

Re: Union All problem

Hi jporell

When it comes to hard coded values, UNION and UNION all always takes the first query's number characters available. So its always better to cast it.