你好,我有这个sql
SELECT TOP 1 message,ticketid,Sender FROM Messages ORDER BY ID DESC WHERE ticketid = '2'
每次我尝试插入它时,都会收到此错误消息
Error in query (1064): Syntax error near '1 message,ticketid,Sender FROM Messages ORDER BY ID DESC WHERE ticketid = '2'' at line 1
名为Messages的Btw表具有id,message,ticketid和Sender
任何想法如何解决?
答案 0 :(得分:0)
MSSql has TOP, MySql has LIMIT
因此删除顶部并添加一个限制。
并将ORDER BY放在WHERE子句之后。
SELECT message, ticketid, Sender
FROM Messages
WHERE ticketid = '2'
ORDER BY ID DESC
LIMIT 1
此外,在调试时,将SQL全部放在1行上将对出现问题的哪一行产生较小的有意义的错误。