我在使用MySQL查询时遇到问题,在该查询中我得到了一个带有LIMIT 1的行.但是,将其与order一起使用时,它不起作用.
在mysql工作台中运行的查询如下:
select * from train t
where t.togId = 1125
and t.tilDato >= '2013-12-20'
order by t.fraDato LIMIT 1;
但是,当我通过javacode和在我的服务器上运行此消息时,得到此stacktrace:
Exception Description:
Syntax error parsing [select t from train t where t.togId = :togId
and t.tilDato >= :todaysdate order by t.fraDato LIMIT 1].
[102, 103] The ORDER BY clause has 't.fraDato ' and 'LIMIT '
that are not separated by a comma.
[108, 109] The ORDER BY clause has 'LIMIT ' and '1' that are not separated by a comma.
查询是这样创建的:
Query query = em.createQuery("select t from train t where t.togId = :togId" +
" and t.tilDato >= :todaysdate order by t.fraDato LIMIT 1")
.setParameter("togId", togId)
.setParameter("todaysdate", new Date());