#1235-此版本的MariaDB尚不支持MySQL中的“ LIMIT&IN / ALL / ANY / SOME子查询”

时间:2019-05-13 15:09:25

标签: sql subquery mariadb limit

这是我的MySQL查询:

select t.*
from hr_pangkat t
where t.oID >= any (select t2.oID
                   from hr_pangkat t2
                   where t2.pegawaiID = t.pegawaiID
                   order by t2.oID asc
                   offset 1 limit 1
                  );

它显示错误:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'offset 1 limit 1
                  ) LIMIT 0, 25' at line 7

如果我删除了偏移量,它仍然显示如下错误:

#1235 - This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'

如何解决?

我正在使用 MySQL 5.6

1 个答案:

答案 0 :(得分:2)

不需要any

select t.*
from hr_pangkat t
where t.oID >= (select t2.oID
                from hr_pangkat t2
                where t2.pegawaiID = t.pegawaiID
                order by t2.oID asc
                offset 1 limit 1
               );

但是,如果只有一行,则失败。因此,您可以添加:

select t.*
from hr_pangkat t
where t.oID >= coalesce( (select t2.oID
                          from hr_pangkat t2
                          where t2.pegawaiID = t.pegawaiID
                          order by t2.oID asc
                          offset 1 limit 1
                         ), t.oID
                       );