473,394 Members | 1,481 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Union Problem

hi all,

i'm new to db2 and i have a simple question ..
Using db2 ver 7.
i have a table named 'Locations' with three varchar columns
LocId,LocDesc,LocType

when i execute >
select * from Locations union all select LocId,LocDesc,LocType from
Locations
it causes an error

and when i execute >
select * from Locations union all select * from Locations
it works.

i know you asking yourself why this mad man write this union.

actually this is a situation i asked to explain from one of my friends
...

any help please
thanks

atef

Nov 12 '05 #1
6 2016
at*********@hotmail.com wrote:
hi all,

i'm new to db2 and i have a simple question ..
Using db2 ver 7.
i have a table named 'Locations' with three varchar columns
LocId,LocDesc,LocType

when i execute >
select * from Locations union all select LocId,LocDesc,LocType from
Locations
it causes an error

and when i execute >
select * from Locations union all select * from Locations
it works.

i know you asking yourself why this mad man write this union.

actually this is a situation i asked to explain from one of my friends
..

any help please
thanks

atef

Atef,

What's the exact error message?
The error condition which I deem to be most likley would be that the
columns are defined in a different order than you think.
So the second UNION ALL branches column order does not match the first.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #2
Serge

thanks for your reply
What's the exact error message? i'm using oledb driver to connect , and it produces a strange error
(internal error 3119) !!!
The error condition which I deem to be most likley would be that the
columns are defined in a different order than you think.
So the second UNION ALL branches column order does not match the first.


I'm sure the columns order is correct
and from my knowledge in other DBMS (SQL , Sybase) the order of columns
is not an issue if we use a column name not a constants

example)
if table1 contains 3 columns c1,c2,c3 .

select * from table1 union all select c1,c2,c3 from table1
should works even if the order is not matched

do you think aliases could be the reason !?

as i said before i'm new to db2 (just started from 3 days)..

thanks again ,waiting for any help

Atef

Nov 12 '05 #3
<at*********@hotmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...

I'm sure the columns order is correct
and from my knowledge in other DBMS (SQL , Sybase) the order of columns
is not an issue if we use a column name not a constants

example)
if table1 contains 3 columns c1,c2,c3 .

select * from table1 union all select c1,c2,c3 from table1
should works even if the order is not matched

do you think aliases could be the reason !?

as i said before i'm new to db2 (just started from 3 days)..

thanks again ,waiting for any help

Atef

In DB2 the columns in both sides of a UNION must have the same length and
data type. That means the first column must match the first column, the
second column must match the second column, and so forth. So it is always
best to specifically list the column names on all parts of a UNION. Using
Select * should be avoided for anything but casual adhoc use.
Nov 12 '05 #4
at*********@hotmail.com wrote:
Serge

thanks for your reply
What's the exact error message?


i'm using oledb driver to connect , and it produces a strange error
(internal error 3119) !!!

The error condition which I deem to be most likley would be that the
columns are defined in a different order than you think.
So the second UNION ALL branches column order does not match the first.

I'm sure the columns order is correct
and from my knowledge in other DBMS (SQL , Sybase) the order of columns
is not an issue if we use a column name not a constants

example)
if table1 contains 3 columns c1,c2,c3 .

select * from table1 union all select c1,c2,c3 from table1
should works even if the order is not matched

do you think aliases could be the reason !?

as i said before i'm new to db2 (just started from 3 days)..

thanks again ,waiting for any help

Atef

Well, first order of buisness is to get the OLEDB out of the way as cause.
Can you connect using the command line processor (CLP)?
Then type the statement from there as we see where we get.
My earlier comment was geared towards questioning whether the table is
truly defined as (c1, c2, c3) and not e.g. (c2, c1, c3).

I would still like to see the error message, weird or not....

Cheers
Serge

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #5
I know it sounds strange but I have encountered similar problems in the
past. Instead of writing:

select * from x UNION ALL select c1, c2, c3 from x

try:

select c1, c2, c3 from x UNION ALL select * from x

Sometimes, specifying individual columns in the first part of the quey
helps over specifying "*".

HTH

David

Nov 12 '05 #6
bones wrote:
I know it sounds strange but I have encountered similar problems in the
past. Instead of writing:

select * from x UNION ALL select c1, c2, c3 from x

try:

select c1, c2, c3 from x UNION ALL select * from x

Sometimes, specifying individual columns in the first part of the quey
helps over specifying "*".

HTH

David

Alright folks.. show me.
I'd like to see a repro script :-)
Also I next the exact version of DB2 and platform (zOS, LUW).
DB2 for zOS supports a ROWID column.
I wonder whether there is confusion whether it shows on '*'.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ricky Lung | last post by:
struct Foo { union { int& i; float& j; }; Foo(int& val) : i((int&)val), j((float&)val) {} };
2
by: Gerry | last post by:
I am relatively new to DB2 and having a problem with a simple union statement. Running Db2UDB version 8.1.1 on Aix 5.1 The union and union all SQL statements I am running produce the same...
1
by: Jeff Blee | last post by:
I hope someone can help me get this graph outputing in proper order. After help from Tom, I got a graph to display output from the previous 12 months and include the average of that output all in...
2
by: Barry Schwarz | last post by:
Given a union of the form union { T1 m1; T2 m2;}obj; where T1 and T2 are different scalar (non-aggregate) types. The C99 standard states that obj.m1 = value; if (obj.m2 ... invokes...
3
by: mikes | last post by:
I have 2 separate queries, which effectively are the same except they draw data from separate tables. Both tables are (design-wise) identical, only the data is different. for each query, there are...
7
by: KoliPoki | last post by:
Hello every body. I have a small issue. Problem: I have a table with 4 descriptor columns (type). I need to formulate a query to retrieve a count for each type so I can group by...etc. The...
30
by: Yevgen Muntyan | last post by:
Hey, Why is it legal to do union U {unsigned char u; int a;}; union U u; u.a = 1; u.u; I tried to find it in the standard, but I only found that
5
by: wugon.net | last post by:
question: db2 LUW V8 UNION ALL with table function month() have bad query performance Env: db2 LUW V8 + FP14 Problem : We have history data from 2005/01/01 ~ 2007/05/xx in single big...
18
by: Bryan Parkoff | last post by:
I hate using struct / union with dot between two words. How can I use one word instead of two words because I want the source code look reading clear. three variables are shared inside one...
3
by: SRK | last post by:
Hi, I wanted to use an anonymous union within an structure something like below - struct Test { union { std::string user; //char user; std::string role; //char role;
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.