【发布时间】:2014-08-06 01:18:56
【问题描述】:
我需要使用此查询从表中获取数据:
(select columns
from tableX
join tableZ
on tableX.id1 = tableZ.other_id)
union all
(select columns
from tableX
join tableZ
on tableX.id2 = tableZ.other_id)
LIMIT num1, num2
没有LIMIT,我的查询构建器会得到正确的结果,如下所示(让$first 成为select 的第一个查询,$second 是另一个select 查询):
$first->unionAll($second)->get();
当我尝试输入skip 和/或take 时,结果与上面的第一个查询不同。
$first->unionAll($second)->take(num1)->skip(num2)->get();
来自上述构建器的结果查询(我从DB::getQueryLog() 得到)类似于:
(select columns
from tableX
join tableZ
on tableX.id1 = tableZ.other_id LIMIT num1, num2)
union all
(select columns
from tableX
join tableZ
on tableX.id2 = tableZ.other_id)
这当然会产生不正确的结果。有谁知道进行第一个查询的解决方法是什么?谢谢!
【问题讨论】:
标签: php laravel-4 eloquent query-builder