Two joins using query builder

Hi All!

I have three tables :

  • Categories[has its own id field]

  • Sub_categories[has its own id and main_category_id fields]

  • Items[has its own id and sub_category_id fields]

I need all items on main_category id =1…

My sql query looks like this :

SELECT * FROM items i INNER JOIN sub_categories sc ON = i.sub_category_id INNER JOIN categories c ON = sc.main_category_id WHERE sc.main_category_id = 1…

now with query builder:

 $query= Yii::app()->db->createCommand()


->from('items i')

->join(‘sub_categories sc’, ‘ = i.sub_category_id’)

How can I implement the 2nd join here?

I’d really appreciate any help!

Quite simple:

$query= Yii::app()->db->createCommand()


->from('items i')

->join('sub_categories sc', ' = i.sub_category_id')

->join('categories c',' = sc.main_category_id');