Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Is it possible to write multiple SELECTs using DB::select() than raw DB::query()?
  • SELECT tt.company_name, tt.name, tt.prefecture, ta.action_datetime, tar.result_disp
                        FROM (
                        SELECT *
                        FROM tbl_actions t1
                        WHERE action_datetime = (SELECT MAX(action_datetime) FROM tbl_actions t2 WHERE t1.target_id = t2.target_id GROUP BY target_id)
                        ) ta
                    JOIN tbl_targets tt
                    ON ta.target_id = tt.id
                    JOIN tbl_mst_action_results tar
                    ON ta.action_result_id = tar.id;
  • HarroHarro
    Accepted Answer
    You can just construct two queries, and use one in the other as a subquery:

    $subquery = DB::select('id')->from('table');
    $result = DB::select()->from('othertable')->where('foreignkey', 'in', $subquery)->execute();
  • Thank you very much Mr. Harro Verton

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion