我有一個MySQL查詢的問題,我得到一個限制1行。但是,當它與它一起使用時,它不起作用。ORDER BY與LIMIT和MySQL
是在MySQL工作臺工作的查詢如下:
select * from train t
where t.togId = 1125
and t.tilDato >= '2013-12-20'
order by t.fraDato LIMIT 1;
然而,當我通過javacode和我的服務器即時得到這個堆棧跟蹤運行以下命令:
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());
代替'有選擇t''選擇*' – AgRizzo
也可以做'選擇T *'。 –
在您的工作臺查詢中,您已選擇*。你的java代碼有select t。除非你的列車表有一個名爲t的列,否則你會得到某種錯誤。 –