MySql查询不起作用给我一个偏移错误

时间:2014-07-11 12:49:30

标签: mysql

这是我的SQL查询

 SELECT tl.* 
   FROM tbl_listing tl 
   LEFT 
   JOIN tbl_sub_category tsc 
     ON tl.subcategory = tsc.id 
  WHERE status_mode = 1 
    AND transaction_complete = 1 
    AND is_deleted != 1 
    AND tl.status IN (10,11,28,12) 
  ORDER  
     BY tl.status ASC 
 OFFSET 1

以下是错误消息:

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 1' at line 12 

提前致谢

2 个答案:

答案 0 :(得分:0)

基本上,用LIMIT替换OFFSET就足够了。

select tl.* from tbl_listing as tl left join `tbl_sub_category` as tsc on 
tl.subcategory = tsc.id where status_mode = '1' and transaction_complete = '1' and 
is_deleted != '1' and tl.status in (10,11,28,12) ORDER BY tl.status ASC LIMIT 1

您可以在LIMIT中使用LIMIT 0中的附加参数来限制从0到2的记录。

答案 1 :(得分:0)

偏移量必须与限制

一起使用

查询应该是

select tl.* 
from tbl_listing as tl 
left join `tbl_sub_category` as tsc on tl.subcategory = tsc.id 
where status_mode = '1' 
  and transaction_complete = '1' 
  and is_deleted != '1' 
  and tl.status in (10,11,28,12) 
ORDER BY tl.status ASC 
LIMIT 10 OFFSET 1;