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 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
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
<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. 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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Ricky Lung |
last post by:
struct Foo {
union {
int& i;
float& j;
};
Foo(int& val) :
i((int&)val), j((float&)val)
{}
};
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
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...
|
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;
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
| |