Re: Issue with COUNT function

2011-01-21 Thread Dag H. Wanvik
Chris Wilson  writes:

> I think that every sub-SELECT must have a table alias in Derby, so add "AS 
> t" to the end of the query (after the closing parenthesis) and it might 
> work :)

This is correct, cf syntax here:

http://db.apache.org/derby/docs/10.7/ref/rrefsqlj33215.html#rrefsqlj33215

When you have a table subquery, the correlation name is mandatory. The
"AS" is optional.

Dag


Re: Issue with COUNT function

2011-01-21 Thread NBW
Chris,

Thanks for your reply. I added the 'AS t' as you suggested and now it works
with Derby. The problem now is that using 'AS t' breaks running the query in
Oracle.  The Derby reference guide doesn't mention the need for the table
alias. I wonder if this is a bug.

-Noah

On Fri, Jan 21, 2011 at 1:03 PM, Chris Wilson  wrote:

> Hi NBW,
>
> On Fri, 21 Jan 2011, NBW wrote:
>
> > SELECT COUNT(*) FROM (SELECT file.md5, instCollection.collectionId FROM
> > file, collection leafCollection, collection instCollection WHERE
> > (file.status=1 OR file.status=2) and file.collectionId =
> > leafCollection.collectionId AND leafCollection.instanceCollectionId =
> > instCollection.collectionId GROUP BY file.md5,
> instCollection.collectionId)
> >
> > That query under Oracle works fine. Under Derby I get the following
> error:
> >
> > [42X01][3] Syntax error: Encountered "" at line 1, column 313.
> >
> > If I run the query without the SELECT COUNT(*) it will run fine in Derby
> > too, but I am trying to get the count :-)
> >
> > I feel like I must be missing something obvious here.
>
> I think that every sub-SELECT must have a table alias in Derby, so add "AS
> t" to the end of the query (after the closing parenthesis) and it might
> work :)
>
> Cheers, Chris.
> --
> Aptivate | http://www.aptivate.org | Phone: +44 1223 760887
> The Humanitarian Centre, Fenner's, Gresham Road, Cambridge CB1 2ES
>
> Aptivate is a not-for-profit company registered in England and Wales
> with company number 04980791.


Re: Issue with COUNT function

2011-01-21 Thread Pavel Bortnovskiy
I'd like to chime in and say that we run such SELECT COUNT(*) queries all 
the time in Derby and have never encountered a problem.
Don't think that "AS" aliasing is necessary.



From:
Chris Wilson 
To:
Derby Discussion 
Date:
01/21/2011 01:07 PM
Subject:
Re: Issue with COUNT function



Hi NBW,

On Fri, 21 Jan 2011, NBW wrote:

> SELECT COUNT(*) FROM (SELECT file.md5, instCollection.collectionId FROM
> file, collection leafCollection, collection instCollection WHERE
> (file.status=1 OR file.status=2) and file.collectionId =
> leafCollection.collectionId AND leafCollection.instanceCollectionId =
> instCollection.collectionId GROUP BY file.md5, 
instCollection.collectionId)
> 
> That query under Oracle works fine. Under Derby I get the following 
error:
> 
> [42X01][3] Syntax error: Encountered "" at line 1, column 313.
> 
> If I run the query without the SELECT COUNT(*) it will run fine in Derby
> too, but I am trying to get the count :-)
> 
> I feel like I must be missing something obvious here. 

I think that every sub-SELECT must have a table alias in Derby, so add "AS 

t" to the end of the query (after the closing parenthesis) and it might 
work :)

Cheers, Chris.
-- 
Aptivate | http://www.aptivate.org | Phone: +44 1223 760887
The Humanitarian Centre, Fenner's, Gresham Road, Cambridge CB1 2ES

Aptivate is a not-for-profit company registered in England and Wales
with company number 04980791.





Jefferies archives and monitors outgoing and incoming e-mail. The contents of 
this email, including any attachments, are confidential to the ordinary user of 
the email address to which it was addressed. If you are not the addressee of 
this email you may not copy, forward, disclose or otherwise use it or any part 
of it in any form whatsoever. This email may be produced at the request of 
regulators or in connection with civil litigation. Jefferies accepts no 
liability for any errors or omissions arising as a result of transmission. Use 
by other than intended recipients is prohibited.  In the United Kingdom, 
Jefferies operates as Jefferies International Limited; registered in England: 
no. 1978621; registered office: Vintners Place, 68 Upper Thames Street, London 
EC4V 3BJ.  Jefferies International Limited is authorised and regulated by the 
Financial Services Authority.

Re: Issue with COUNT function

2011-01-21 Thread Chris Wilson
Hi NBW,

On Fri, 21 Jan 2011, NBW wrote:

> SELECT COUNT(*) FROM (SELECT file.md5, instCollection.collectionId FROM
> file, collection leafCollection, collection instCollection WHERE
> (file.status=1 OR file.status=2) and file.collectionId =
> leafCollection.collectionId AND leafCollection.instanceCollectionId =
> instCollection.collectionId GROUP BY file.md5, instCollection.collectionId)
> 
> That query under Oracle works fine. Under Derby I get the following error:
> 
> [42X01][3] Syntax error: Encountered "" at line 1, column 313.
> 
> If I run the query without the SELECT COUNT(*) it will run fine in Derby
> too, but I am trying to get the count :-)
> 
> I feel like I must be missing something obvious here. 

I think that every sub-SELECT must have a table alias in Derby, so add "AS 
t" to the end of the query (after the closing parenthesis) and it might 
work :)

Cheers, Chris.
-- 
Aptivate | http://www.aptivate.org | Phone: +44 1223 760887
The Humanitarian Centre, Fenner's, Gresham Road, Cambridge CB1 2ES

Aptivate is a not-for-profit company registered in England and Wales
with company number 04980791.

Issue with COUNT function

2011-01-21 Thread NBW
I am using Derby 10.4 supplied with JavaEE5 SDK/Glassfish 2.1. The following
function works perfectly well with Oracle 10g XE using the Oracle ojdbc6
driver -

SELECT COUNT(*) FROM (SELECT file.md5, instCollection.collectionId FROM
file, collection leafCollection, collection instCollection WHERE
(file.status=1 OR file.status=2) and file.collectionId =
leafCollection.collectionId AND leafCollection.instanceCollectionId =
instCollection.collectionId GROUP BY file.md5, instCollection.collectionId)

That query under Oracle works fine. Under Derby I get the following error:

[42X01][3] Syntax error: Encountered "" at line 1, column 313.

If I run the query without the SELECT COUNT(*) it will run fine in Derby
too, but I am trying to get the count :-)

I feel like I must be missing something obvious here.

Thanks,

-Noah