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 > Database Server Software > Informix > Informix SQL - Creating subqueries in the SELECT statment

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-15-08, 15:48
skisalomon77 skisalomon77 is offline
Registered User
 
Join Date: May 2008
Posts: 21
Informix SQL - Creating subqueries in the SELECT statment

I'm having issues creating a subquery in Informix. I'm using the Informix 3.33 driver.

I'm trying to combine this query, which works perfectly fine by itself...

SELECT sl_store,
COUNT(sl_store) AS Total
FROM informix.sales
GROUP BY sl_store

...with this query, which also works perfectly fine by itself...

SELECT sl_store, sl_inv_num,
COUNT(sl_inv_num) AS NumOccurrences
FROM informix.sales
WHERE sl_date between '06-20-2007' AND '07/31/2007'
GROUP BY sl_store, sl_inv_num
HAVING ( COUNT(sl_inv_num) >= 1 )

...to give me this query, which is yielding a -201 error, which either means there is extra or missing punctuation, or that something is mispelled.

SELECT sl_store,
COUNT(sl_store) AS Total
FROM (SELECT sl_store, sl_inv_num,
COUNT(sl_inv_num) AS NumOccurrences
FROM informix.sales
WHERE sl_date between '06-20-2007' AND '07/31/2007'
GROUP BY sl_store, sl_inv_num
HAVING ( COUNT(sl_inv_num) >= 1 ))
GROUP BY sl_store

I'm not seeing the issue. Hopefully someone else can. Please let me know if I wasn't clear enough. What I'm trying to do makes sense in my head, but may not make sense with someone else.
Reply With Quote
  #2 (permalink)  
Old 05-15-08, 16:07
ceinma ceinma is offline
Registered User
 
Join Date: Apr 2007
Location: Jundiai / SP - Brasil
Posts: 311
I do not see anything wrong...

But this syntax is supported only after IDS version 10 ....
__________________
________________________________________
César Inacio Martins
Jundiai / SP - Brasil
http://www.imartins.com.br/informix - em Português
http://www.imartins.com.br/informix - English (translated by Google).
________________________________________

Last edited by ceinma; 05-15-08 at 16:11.
Reply With Quote
  #3 (permalink)  
Old 05-15-08, 18:53
skisalomon77 skisalomon77 is offline
Registered User
 
Join Date: May 2008
Posts: 21
Thanks ceinma!

Informix is new for me. I've used MS SQL Server platforms for a long time. I believe we're using IDS version 9.3. I just downloaded the SQL Syntax Guide for this version. I'll play around with it.
Reply With Quote
  #4 (permalink)  
Old 05-15-08, 21:42
ceinma ceinma is offline
Registered User
 
Join Date: Apr 2007
Location: Jundiai / SP - Brasil
Posts: 311
to work around.. try this..

SELECT sl_store, sl_inv_num,
COUNT(sl_inv_num) AS NumOccurrences
FROM informix.sales
WHERE sl_date between '06-20-2007' AND '07/31/2007'
GROUP BY sl_store, sl_inv_num
HAVING ( COUNT(sl_inv_num) >= 1 )
INTO TEMP TP_SALES WITH NO LOG;

SELECT sl_store,
COUNT(sl_store) AS Total
FROM (TP_SALES)
GROUP BY sl_store;
__________________
________________________________________
César Inacio Martins
Jundiai / SP - Brasil
http://www.imartins.com.br/informix - em Português
http://www.imartins.com.br/informix - English (translated by Google).
________________________________________
Reply With Quote
  #5 (permalink)  
Old 05-16-08, 10:24
skisalomon77 skisalomon77 is offline
Registered User
 
Join Date: May 2008
Posts: 21
I just had to remove the () from TP_SALES in the second SELECT query and it worked like a charm.

César...thanks for your help!
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