Unix Technical Forum

Num query fields affects num rows

This is a discussion on Num query fields affects num rows within the DB2 forums, part of the Database Server Software category; --> Hello, When I remove MYTABLE5.HAPPYCAPACITY from the SELECT clauses of the following query, the number of rows returned drops ...


Go Back   Unix Technical Forum > Database Server Software > DB2

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-26-2008, 07:54 PM
Eric Goforth
 
Posts: n/a
Default Num query fields affects num rows

Hello,

When I remove MYTABLE5.HAPPYCAPACITY from the SELECT clauses of the
following query, the number of rows returned drops from 28 to 24. If
I put it back in it goes back up to 28. Any idea how this is
possible?

Thanks,
Eric

SELECT
MYTABLE2.ACCOUNTID, MYTABLE2.HostOwnershipType AS COAPPTYPE,
MYTABLE5.HAPPYCAPACITY
FROM MYTABLE1, CUSTOMERS, SPECIALCUSTOMERS MYTABLE2,
SPECIALCUSTOMERS MYTABLE3, MYTABLE5
WHERE MYTABLE1.HAPPY = 'Yes'
AND MYTABLE1.BUDDYNAME = (CUSTOMERS.FIRSTNAME || ' ' ||
CUSTOMERS.LASTNAME)
AND (CUSTOMERS.MIDDLENAME IS NULL OR CUSTOMERS.MIDDLENAME = '')
AND CUSTOMERS.CUSTOMERID = MYTABLE2.CUSTOMERID
AND MYTABLE1.CUSTOMERID = MYTABLE3.CUSTOMERID
AND MYTABLE1.CUSTOMERID = MYTABLE5.CUSTOMERID
UNION
SELECT
MYTABLE2.ACCOUNTID, MYTABLE2.HostOwnershipType AS COAPPTYPE,
MYTABLE5.HAPPYCAPACITY
FROM MYTABLE1, CUSTOMERS, SPECIALCUSTOMERS MYTABLE2,
SPECIALCUSTOMERS MYTABLE3, MYTABLE5
WHERE MYTABLE1.HAPPY = 'Yes'
AND MYTABLE1.BUDDYNAME = (CUSTOMERS.FIRSTNAME || ' ' ||
CUSTOMERS.MIDDLENAME || ' ' || CUSTOMERS.LASTNAME)
AND CUSTOMERS.MIDDLENAME IS NOT NULL AND CUSTOMERS.MIDDLENAME <> ''
AND CUSTOMERS.CUSTOMERID = MYTABLE2.CUSTOMERID
AND MYTABLE1.CUSTOMERID = MYTABLE3.CUSTOMERID
AND MYTABLE1.CUSTOMERID = MYTABLE5.CUSTOMERID;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-26-2008, 07:54 PM
miro flasza
 
Posts: n/a
Default Re: Num query fields affects num rows

UNION removes duplicates from the result, try UNION ALL if you want
all rows returned.

Regards,
Miro

Eric Goforth wrote:

> Hello,
>
> When I remove MYTABLE5.HAPPYCAPACITY from the SELECT clauses of the
> following query, the number of rows returned drops from 28 to 24. If
> I put it back in it goes back up to 28. Any idea how this is
> possible?
>
> Thanks,
> Eric
>
> SELECT
> MYTABLE2.ACCOUNTID, MYTABLE2.HostOwnershipType AS COAPPTYPE,
> MYTABLE5.HAPPYCAPACITY
> FROM MYTABLE1, CUSTOMERS, SPECIALCUSTOMERS MYTABLE2,
> SPECIALCUSTOMERS MYTABLE3, MYTABLE5
> WHERE MYTABLE1.HAPPY = 'Yes'
> AND MYTABLE1.BUDDYNAME = (CUSTOMERS.FIRSTNAME || ' ' ||
> CUSTOMERS.LASTNAME)
> AND (CUSTOMERS.MIDDLENAME IS NULL OR CUSTOMERS.MIDDLENAME = '')
> AND CUSTOMERS.CUSTOMERID = MYTABLE2.CUSTOMERID
> AND MYTABLE1.CUSTOMERID = MYTABLE3.CUSTOMERID
> AND MYTABLE1.CUSTOMERID = MYTABLE5.CUSTOMERID
> UNION
> SELECT
> MYTABLE2.ACCOUNTID, MYTABLE2.HostOwnershipType AS COAPPTYPE,
> MYTABLE5.HAPPYCAPACITY
> FROM MYTABLE1, CUSTOMERS, SPECIALCUSTOMERS MYTABLE2,
> SPECIALCUSTOMERS MYTABLE3, MYTABLE5
> WHERE MYTABLE1.HAPPY = 'Yes'
> AND MYTABLE1.BUDDYNAME = (CUSTOMERS.FIRSTNAME || ' ' ||
> CUSTOMERS.MIDDLENAME || ' ' || CUSTOMERS.LASTNAME)
> AND CUSTOMERS.MIDDLENAME IS NOT NULL AND CUSTOMERS.MIDDLENAME <> ''
> AND CUSTOMERS.CUSTOMERID = MYTABLE2.CUSTOMERID
> AND MYTABLE1.CUSTOMERID = MYTABLE3.CUSTOMERID
> AND MYTABLE1.CUSTOMERID = MYTABLE5.CUSTOMERID;


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:48 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com