Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Newbie: combining two selects

Re: Newbie: combining two selects

From: Martin T. <bilbothebagginsbab5_at_freenet.de>
Date: 31 Jul 2006 14:12:10 -0700
Message-ID: <1154380330.224566.326030@75g2000cwc.googlegroups.com>


tuxfan wrote:
> I am trying to combine the following two SQL statements into
> one select statement. The first column in both statements
> are the same. It looks like I need a nested statement, but
> I don't know how to do that.
>
>
> SELECT node_data.server, COUNT ( node_data.node_name )
> FROM node_data, account
> WHERE node_data.node_name = account.node_name
> AND acct_number = '7777'
> GROUP BY node_data.server
>
> SELECT node_data.server, COUNT ( node_data.node_name )
> FROM node_data, account
> WHERE node_data.node_name = account.node_name
> AND acct_number = '7777'
> AND lastacct < 2
> GROUP BY node_data.server

What do you mean by "combine"?

The 1st will give you some aggregate COUNT over (7777) and the 2nd will give you some aggregate count over (7777 && <2)

You _could_ do (please someone shout at me if that's bad style):

SELECT node_data.server server_1, COUNT ( node_data.node_name ) count_1, NULL server_2, NULL count_2
FROM node_data, account
WHERE node_data.node_name = account.node_name AND acct_number = '7777'
GROUP BY node_data.server
UNION
SELECT NULL, NULL, node_data.server, COUNT ( node_data.node_name ) FROM node_data, account
WHERE node_data.node_name = account.node_name AND acct_number = '7777'
AND lastacct < 2
GROUP BY node_data.server

... but then again that is probably not what you wanted?

best,
Martin Received on Mon Jul 31 2006 - 16:12:10 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US