gpt4 book ai didi

php - orderBy 在 Laravel 5 中不起作用

转载 作者:可可西里 更新时间:2023-11-01 08:05:22 25 4
gpt4 key购买 nike

我正在使用以下查询。 orderBy 在以下查询中不起作用。此查询在 localhost 中有效,但在 Online Server 中无效。

return DB::table('reports')
->leftJoin('sources', 'reports.report_source_id', '=', 'sources.id')
->select('*')
->orderBy('report_id', 'desc')
->take(10)
->get();

最佳答案

尝试为每个表设置一个别名,然后在 orderBy 上使用所需的别名

如果两个表中都有一个 report_id,它将不知道要使用哪个,如果您查找它可能会抛出错误。

return DB::table('reports as r')
->leftJoin('sources as s', 'r.report_source_id', '=', 's.id')
->select('*')
->orderBy('r.report_id', 'desc')
->take(10)
->get();

关于php - orderBy 在 Laravel 5 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31608034/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com