zend_db_select join using 3 or more tables

430 views Asked by At

So Zend_db_select has the methods

  `joinUsing(table, join, [columns]) and joinInnerUsing(table, join, [columns])`

  `joinLeftUsing(table, join, [columns])`

  `joinRightUsing(table, join, [columns])`

  `joinFullUsing(table, join, [columns])`

etc

but what if you want to join 3 or more tables (eg for a many to many association)....eg: this query:

 SELECT * FROM (j LEFT JOIN e ON j.id = e.eee) LEFT JOIN w ON w.www = e.id

how would you go about doing this with zend_db_select

2

There are 2 answers

0
S L On BEST ANSWER

Try doing ... but i am not so sure works with two fields but have not tried with 3 fields

$dbmodel->select(false)
    ->setIntegrityCheck(false)
    ->from(array('t1' => 'table1'))
    ->joinLeft(array('t2' => 'table2'),                                             
        't1.somefeild = t2.somefeild')
    ->joinLeft(array('t3' => 'table3'),                                             
        't2.somefeild = t3.somefeild')

you try to build query, and also you can check query by die((string)$select)

0
KomarSerjio On

Try use subquery and Zend_Db_Expr. Read more here.