1

use php laravel select data, how to add outer apply to laravel code?

    $data_result = tableA_model::where(function($query) use ($input) {
      $query->where('city', '=',  $input['city'] );
    }

i need sql like:

select *, (select top 1 name from imglist where id=tableA.id order by cover desc) as picname FROM tableA where ...

or

select * from tableA outer apply (select top 1 name as picname from imglist where id=tableA.id order by cover desc) img where ....

how can i get such a outer apply in laravel ?

Hao Han
  • 13
  • 4
  • Not an answer but you can probably achieve the same result using a `LEFT JOIN` which you can actually code using `leftJoin(...)` of the query builder – apokryfos Aug 09 '19 at 10:07
  • You can use a [raw expression](https://laravel.com/docs/5.8/queries#raw-expressions). – mwal Aug 09 '19 at 10:02
  • or how can take tableA item and get item first photo (in table:imglist) use one sql get in laravel? – Hao Han Aug 10 '19 at 15:25
  • i use ''->select(DB::raw("*,(select top 1 name from imglist where imglist.housen=tableA.housen and types='ding' order by cover desc) as picname"));'' solve this, thanks – Hao Han Aug 12 '19 at 02:42

0 Answers0