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']
From stackoverflow
-
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 1off the end and use.setMaxResults(1)on the query.Bogdan : 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 JPAlakshmi : What about when you want to use a subquery select inside of your main select statement. It needs to return only 1 item.oedo : 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?lakshmi : Thanks for your suggession.I used single Query its working.. Thanks a lot..oedo : sweet, glad i could help :)Bogdan : good catch oedo! I didn't notice it was the same object :)
0 comments:
Post a Comment