tags:

views:

107

answers:

1

Im getting following error while running the query.

org.hibernate.hql.ast.QuerySyntaxException: expecting CLOSE, found 'LIMIT' near line 1, column 194 [from com.claystone.db.Gpsdata where id.mobileunitid = '2090818044' and gpsdate in (select id.gpsdate from com.claystone.db.Gpsdata where id.mobileunitid = '2090818044' ORDER BY id.gpsdate DESC LIMIT 1 )  and gpsstatus='true']

This is my Query.Please give the suggession what is the mistake in this query?

data=session.createQuery[from com.claystone.db.Gpsdata where id.mobileunitid = '2090818044' and gpsdate in (select id.gpsdate from com.claystone.db.Gpsdata where id.mobileunitid = '2090818044' ORDER BY id.gpsdate DESC LIMIT 1 )  and gpsstatus='true']
+3  A: 

why are you using the subquery? just do it like this :

data=session.createQuery[from com.claystone.db.Gpsdata where id.mobileunitid = '2090818044' and gpsstatus='true' ORDER BY id.gpsdate DESC LIMIT 1]

you might need to take the LIMIT 1 off the end and use .setMaxResults(1) on the query.

oedo
I believe he wants to limit the subquery result to 1 not the whole result set :). I'd be interested too to know how is done in JPA
Bogdan
What about when you want to use a subquery select inside of your main select statement. It needs to return only 1 item.
lakshmi
but the subquery seems to join on the same table/object - so surely you can do it with just a single query/orderby/limit as i've suggested?
oedo
Thanks for your suggession.I used single Query its working.. Thanks a lot..
lakshmi
sweet, glad i could help :)
oedo
good catch oedo! I didn't notice it was the same object :)
Bogdan