cancel
Showing results for 
Search instead for 
Did you mean: 

Union two tables with diffrent count of fields with null and float value

Former Member
0 Kudos

Hello,

i want to union two tables, first one with 3 fields and second one with 4 fields (diffrent count of fields).

I can add null value at end of first select but it does not work with float values in second table. Value form second table is convert to integer.

For example:

select null v1 from sessions

union

select 0.05 v1 from sessions

result is set of null and 0 value.

As workaround i can type:

select null+0.0 v1 from sessions

union

select 0.05 v1 from sessions

or simple change select's order.

Is any better/proper way to do this? Can I somehow set float field type in first select?

Best regards,

Lukasz.

WIN XP, MAXDB 7.6.03

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

what about this:

select float(null,5) v1 from sessions

union

select 0.05 v1 from sessions

lbreddemann
Active Contributor
0 Kudos

Hi Lukasz,

in a UNION statement the first statement defines the structure (number, names and types of fields) of the resultset.

Therefore you have to define a FLOAT field in the first SELECT statement in order to avoid conversion to VARCHAR.

Be aware that NULL and 0.0 are not the same thus NULL+0.0 does not equal NULL.

In fact NULL cannot equal to any number or character value at all.

BTW: you may want to use UNION ALL to avoid the search and removal of duplicates - looks like your datasets won't contain duplicates anyhow...

Regards,

Lars