How to refer outer table in a subquery

Posted 1 year ago by ashwini7

In the below query, getting error on line 7 : Undefined table: ERROR: missing FROM-clause entry for table "C"

how do we refer to outer table in inner subquery ?

  1. AB::with(['A', 'B', 'A.C'])
  2.        ->select('AB.*')
    
  3.       ->whereRaw(function($query) use ($defaultTimeInUTC) {
    
  4.            $query->where('AB.created_at', '<=',
    
  5.               DB::raw("  
    
  6.                    CASE 
    
  7.                       WHEN A.C.default_time is NULL THEN
    
  8.                            timestamp '{$defaultTimeInUTC}'
    
  9.                        ELSE 
    
  10.                            DATE(CURRENT_DATE) - Interval '1 day' + time 'A.C.default_time'
    
  11.                       END  
    
  12.                ")
    
  13.           );
    
  14.        });
    

Please sign in or create an account to participate in this conversation.