Php orderBy不在Laravel 5工作
我正在使用下面的查询orderBy在下面的查询中不起作用。此查询在localhost中工作,但在联机服务器中不工作Php orderBy不在Laravel 5工作,php,mysql,laravel-5,Php,Mysql,Laravel 5,我正在使用下面的查询orderBy在下面的查询中不起作用。此查询在localhost中工作,但在联机服务器中不工作 return DB::table('reports') ->leftJoin('sources', 'reports.report_source_id', '=', 'sources.id') ->select('*') ->orderBy('report_id', 'desc') ->take
return DB::table('reports')
->leftJoin('sources', 'reports.report_source_id', '=', 'sources.id')
->select('*')
->orderBy('report_id', 'desc')
->take(10)
->get();
尝试使用reports.report\u id like
return DB::table('reports')
->leftJoin('sources', 'reports.report_source_id', '=', 'sources.id')
->select('*')
->orderBy('reports.report_id', 'desc')
->take(10)
->get();
尝试为每个表设置别名,然后在orderBy上使用所需的别名 如果两个表中都有一个
report\u 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();
试试这个。。
使用“reports.report_id”
但是您仍然使用
->orderBy('report\u id','desc')
而不是->orderBy('reports.report\u id','desc')
这两个数据库之间是否存在某种差异,比如排序规则或导致该数据库无法工作的原因?当您说它不工作时,查询是否正在运行但没有排序,或者是否有任何错误消息?
return DB::table('reports')
->leftJoin('sources', 'reports.report_source_id', '=', 'sources.id')
->select('*')
->orderBy('reports.report_id', 'desc')
->take(10)
->all();