1
select distinct clientID from Client where clientID not in (select clientID from courseDetails inner join course on coursedetails.courseID = course.courseID where coursedetails.courseID = '$courseID')
select distinct clientID from Client where clientID not in (select clientID from courseDetails inner join course on coursedetails.courseID = course.courseID where coursedetails.courseID = '$courseID')
使用如果您的查詢是一個複雜的問題,那麼你可以使用RAW
查詢在laravel
,如:
$data = DB::select(DB::raw('your query'));
注: DB :: raw()用於創建查詢構建器不再分析的任意SQL命令。因此,他們可以通過SQL注入創建一個攻擊向量。
我給你一個起點:
$results = DB::table('Client')
->whereNotIn('clientID', function($query) use ($courseID) {
$query->select('clientID')
->from('courseDetails')
->join('course', 'courseDetails.courseID', '=', 'course.courseID')
->where('coursedetails.courseID', '=', $courseID);
})->get();
這應該讓你去。你可以調整它,因爲你想獲得預期的結果。
添加到@Mayank的回答,您可以運行原始的SQL,並傳遞參數這樣
$result = DB::select('select distinct... where coursedetails.courseID = ? ', [$courseID]);
請,https://laravel.com/docs/5.4/queries – manian