-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Subselect join
PostPosted: Thu Jul 19, 2007 11:35 am 
Newbie

Joined: Fri May 04, 2007 10:54 am
Posts: 4
Hi everyone,

I've got a problem formulating a HSQL query.
This query works in normal SQL:

SELECT * FROM item, (SELECT id AS sub1,max(version) AS sub2 FROM item GROUP BY id) WHERE id=sub1 AND version=sub2;

An item has a composite primary key (id and version).
I want to get the most current items, thus items with the highest version.

I've tried to convert this SQL query to HSQL like this:

SELECT it FROM Item it,
(SELECT id.id AS sub1,max(id.version) AS sub2 FROM Item GROUP BY id.id)
WHERE it.id.id=sub1 AND it.id.version=sub2

But it doesn't work:
QuerySyntaxException: unexpected token: ( near line 2, column 1

Is it possible to use subselects like this?

Bye
Markus

Hibernate version: 3.2.1


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 19, 2007 1:52 pm 
Newbie

Joined: Fri May 04, 2007 10:54 am
Posts: 4
Sorry, I overread the part in the docs which say: "Note that HQL subqueries may occur only in the select or where clauses."


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.