abu*_*abu 4 php mysql laravel-5
我正在使用以下查询。orderBy在下面的查询中不起作用。此查询在本地主机中有效,但在在线服务器中无效。
return DB::table('reports')
->leftJoin('sources', 'reports.report_source_id', '=', 'sources.id')
->select('*')
->orderBy('report_id', 'desc')
->take(10)
->get();
Run Code Online (Sandbox Code Playgroud)
尝试为每个表设置一个别名,然后在 orderBy 上使用所需的别名
如果两个表中都有 a ,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();
Run Code Online (Sandbox Code Playgroud)