Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
[QueryBuilder] Can I use any joined tables in From cause?
  • Hello.

    (1)I wont to build query like:
    -----------------------------------------------------
    SELECT *
    FROM tbl_a A1 INNER JOIN tbl_b B ON A1.b_id=B.id, tbl_a A2
    WHERE ...
    -----------------------------------------------------

    (2)I wrote it by query builder:
    -----------------------------------------------------
    \DB::select()
    ->from( array('tbl_a', 'A1') )
    ->join( array('tbl_b', 'B'), 'INNER' )
    ->on('A1.b_id', '=', 'B.id')
    ->from( array('tbl_a', 'A2') )
    ->where...
    -----------------------------------------------------

    (3)result:
    -----------------------------------------------------
    SELECT *
    FROM tbl_a A1, tbl_a A2
    INNER JOIN tbl_b B ON A1.b_id=B.id
    WHERE ...

    *** ERROR 1054! ***
    Fuel\Core\Database_Exception [ 1054 ]: Unknown column 'tbl_A1.b_id' ...
    -----------------------------------------------------

    How to order from cause built sequence?
  • Sorry, It's solved.
    I changed 2nd table from from cause to join cause.

     \DB::select()
    ->from( array('tbl_a', 'A1') )
    ->join( array('tbl_b', 'B'), 'INNER' )
    ->on('A1.b_id', '=', 'B.id')
    ->join( array('tbl_a', 'A2') )
    ->where...


Howdy, Stranger!

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

In this Discussion