如何获取不存在连接的记录?

How to get record where join does not exist?

当另一个 table 中没有匹配记录时,如何 select 从一个 table 记录。

$bookings->getQuery()
                ->join('consultation', 'consultation.booking_id', '=', 'bookings.id')
                ->whereRaw('bookings.booking_date  >= CURDATE()')
                ->select('bookings.*')
                ->groupBy('bookings.id');

在上面的查询中,我试图仅在没有针对该预订的咨询时获取预订。如何实现?

通过使用sub_query

->whereNotIn('id', function($query){
  $query->select('booking_id')
  ->from('consultation')
  ->distinct();})->get();