这是我的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
答案 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
);