A company has departments and departments have employees
Each respective table has Id primary key and relations are defined by foreign keys using these Id numbers.
Now I have a CGridView of employees and I would like to show name of department he/she is working in (that is easy) as well as name of the company he/she belongs (difficult).
SELECT COUNT(DISTINCT `t`.`id`)
FROM `employees` `t`
LEFT OUTER JOIN `departments` `department`
ON (`t`.`department_id`=`department`.`id`)
LEFT OUTER JOIN `companies` `company`
ON (`department`.`company_id`=`company`.`id`)
WHERE (`company`.`name` LIKE 'Hewlett%');
Actually, I have a problem with “WHERE” condition - I can’t find good way to put it into search criteria.