我正在使用以下查询。orderBy在下面的查询中不起作用。此查询在本地主机中有效,但在在线服务器中无效。
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();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)