-1

Say I have this bit of SQL:

select * 
from `fluents`
inner join `tests` on `fluents`.`id` = `tests`.`fluent_test_id`
inner join (
    select `fluents`.`id` from `fluents` order by `fluents`.`id` desc limit 10
) as j on `fluents`.`id` = `j`.`id`
order by `fluents`.`created_at`;

I know I could run the raw SQL but as a learning exercise I'm trying to convert it to fluent and failing miserably, is this even possible?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
rich97
  • 2,809
  • 2
  • 28
  • 34

1 Answers1

6

I have done it this way in my project:

DB::table('fluents')->join('tests','tests.fluent_test_id','=','fluents.id')
                    ->join(DB::raw("(select fluents.id from fluents order by `fluents`.`id` desc limit 10) as j"),'j.id','=','fluents.id')
                    ->orderBy('fluents.created_at');

I hope this can be of some help.

saran banerjee
  • 2,895
  • 1
  • 13
  • 12