我想要一个表中的信息,以及是否还有来自另一个表的匹配信息.
这是我的代码
$scoreObject = DB::table('responses')
->select('responses.id', 'responses.questions_id', 'responses.answer_id', 'responses.open_answer', 'responses.user_id', 'responses.scan_id',
'questions.question', 'questions.question_nr', 'questions.type', 'questions.totalsection_id',
'answers.id as answerID', 'answers.answer', 'answers.questions_id', 'answers.points'
)
->Join('answers as answers', 'responses.answer_id', '=', 'answers.id')
->Join('questions as questions', 'answers.questions_id', '=', 'questions.id')
->orderBy('questions.id', 'ASC')
->where('responses.scan_id', $scanid)
->where('responses.user_id', $userid)
->groupBy('questions.id')
->get();
Run Code Online (Sandbox Code Playgroud)
它返回所有与答案匹配的答案(answers.questions_id questions.id').一些响应没有匹配(因为没有respond.answer_id)但我仍然想要响应信息.
我怎样才能在laravel中获得这样一个左外连接?