简体   繁体   English

我的SQL查询出了什么问题?

[英]What's so wrong with my SQL query?

select * from `a2_posts` where `reply_to` = -1 order by `updated_at` desc offset 4;

and I'm getting this message: 我收到这条消息:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'offset 4' at line 1

I'm no sql expert but I really cant figure out what's so wrong with offset. 我不是SQL专家,但我真的无法弄清楚偏移有什么问题。

btw this query was generated by the Eloquent ORM, from this code: 顺便说一句,这个查询是由Eloquent ORM生成的,来自以下代码:

Post::whereReplyTo($request->input('reply_to'))
        ->orderBy('updated_at', 'desc')
        ->offset(Config::PAGE_SIZE * Config::MAX_PAGES)
        ->get();

I just punched the resulting query into PHPMyAdmin to check what was going on and thats what I've got 我只是将生成的查询打入PHPMyAdmin以检查发生了什么,这就是我所拥有的

Do you guys know what's wrong? 你们知道什么是错的吗? the PHPMyAdmin highlighter didnt even highlight the offset keyword. PHPMyAdmin荧光笔甚至没有突出显示偏移关键字。

Thanks in advance 提前致谢

MySQL syntax requires LIMIT x before OFFSET x . MySQL语法在OFFSET x之前需要LIMIT x OFFSET x

Syntax: 句法:

[LIMIT {[offset,] row_count | row_count OFFSET offset}]

It needs to be something like this: 它需要是这样的:

select * from `a2_posts` where `reply_to` = -1 
order by `updated_at` desc 
limit 2 offset 4;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM