If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Easy query help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-08-06, 04:24
archMEL archMEL is offline
Registered User
 
Join Date: Sep 2006
Posts: 8
Easy query help

I want to perform the following query but i dont know how :

select count(num) from X

and I want the X to be a table from the following query :

select table from bla bla bla . . .

This cannot be done by :select count(num) from (select table from bla bla bla) !

How can i build it ??? I have stuck !
Reply With Quote
  #2 (permalink)  
Old 09-08-06, 05:55
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
which database is this? because the method you described should work

what was the actual error message you got?

perhaps you could also show real table and column names so we could see if there is an obvious syntax error
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 09-08-06, 06:03
archMEL archMEL is offline
Registered User
 
Join Date: Sep 2006
Posts: 8
I get a incorrect synbtax :

The query is
select count(distinct timestamp) from (select cf.table from general_cfg cf, can c where cf.x1 = c.y1);

This should have worked ???
Reply With Quote
  #4 (permalink)  
Old 09-08-06, 08:39
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
no, it shouldn't've

the subquery produces an intermediate table result which is used as the data source for the outer query's FROM clause, yes?

well, that intermediate table result has a single column, called "table"

thus, the outer table cannot count the distinct values of a column called "timestamp" because that column doesn't exist
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 09-08-06, 08:52
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Are we trying to sneak up on dynamic SQL here?

-PatP
Reply With Quote
  #6 (permalink)  
Old 09-08-06, 09:32
archMEL archMEL is offline
Registered User
 
Join Date: Sep 2006
Posts: 8
And is there a solution to this problem at last ...?????
Reply With Quote
  #7 (permalink)  
Old 09-08-06, 09:34
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
yes there is!!!!!!!!!!!!
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #8 (permalink)  
Old 09-08-06, 12:23
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Quote:
Originally Posted by archMEL
select count(num) from (select table from bla bla bla)
Add an alias name for the table:
Code:
select count(num) from (select num from table from bla bla bla) AS tmp
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/

Last edited by Peter.Vanroose; 09-08-06 at 15:14.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On