我只想显示表中不同的行,但是这些值必须是最新的,我是从表中的日期开始过滤的。这是我的查询。我得到的结果是日期较旧的行,我猜orderby在这里不起作用。请帮忙。我已经附好桌子了。
$reports= DB::table('resident_assessment')
-where('resident_assessment.assessment_date','<=',$date)
-join('assessment_entry','resident_assessment.assessment_id','=','assessment_entry.assessment_id')
-orderby('resident_assessment.assessment_date','desc')
-distinct()->get();
答案 0 :(得分:2)
SELECT DISTINCT RA.* FROM resident_assessment RA INNER JOIN assessment_entry AE ON
AE.assessment_id = RA.assessment_id
WHERE RA.assessment_date = $date ORDER BY RA.assessment_date desc
这是适合您的任务的select语句。这可能对您有帮助