【发布时间】:2017-03-17 21:13:02
【问题描述】:
在 9900 偏移后,我只获得了 99 条限制 100 的记录。即使我在 db 中有 2,00,000 条记录,并且在两个具有不同的表中都有左连接。我的查询或循环有什么问题
即使我在 phpmyadmin 中尝试了查询,它也给出了相同的结果 99 条记录。
查询
select distinct(table1.id), table2.name, table2.uuid from table1
left join table2 on table1.id = table2.id limit 9900, 100
Laravel 查询:
$this
->database
->table('table1')
->selectRaw('distinct(table1.id), table2.uuid, table2.name')
->leftJoin('table1.id', '=', 'table2.id')
->where('opponent_uID', '>', $uID)
->skip($offset)
->take($limit)
->get();
循环
$limit = 100;
$offset = 0;
while (true) {
$result = $this->query($limit, $offset);
$offset += $limit;
if (empty($result)) {
break;
}
// Logic here
}
【问题讨论】:
-
告诉我们你的数据库中有多少条记录有点没有意义。更相关的是被连接的两个表中的记录数,以及左连接如何增加结果集中可能的记录数。此外,使用
DISTINCT会影响记录数。 -
@TimBiegeleisen 2,00,000 条左连接表中的记录
标签: php mysql laravel orm laravel-5.2