Re: DB_DataObject joinAdd

From: Date: Sat, 25 Dec 2004 01:09:24 +0000
Subject: Re: DB_DataObject joinAdd
References: 1 2  Groups: php.pear.general php.pear.general 
Request: Send a blank email to pear-general+get-16459@lists.php.net to get a copy of this message
The only way I've been able to do this is: function joinAddDept() { $this->_join .= 'LEFT JOIN dept ON (substring(employee.code from 1 for 2) = dept.code)'; } Interestingly, if You start seeing performance issues using INNER JOINS with dataobjects's joins, it may be worth moving the table specific where conditions into the ON .... section of the query. It appears mysql doesnt optimize that for you... Regards Alan Justin Patrin wrote:
On Thu, 23 Dec 2004 00:18:34 +0800, Muhyiddin A.M Hayat <middink@indo.net.id> wrote:
Dear all, I have problem with joinAdd(). I Have 2 tables Employee: code | name -------+---------- GL001 | Mr. Black SL001 | Mr. Brown SL001 | Mr. White Depts: code | name ------+--------- GL | General SL | Sales So, I would like to create sql like below using DB_DataObject SELECT employee.code, employee.name, dept.name AS dept FROM employee LEFT JOIN dept ON (substring(employee.code from 1 for 2) = dept.code) I don't know how to join them using DB_DataObject
You can't. Joins are supposed to join two columns, not a piece of one column with another. You would have to write your own SQL for this. I suggest you break up that Employee.code column to be deptCode and employeeNumber and combine them when you display them (or whatever).


« previous php.pear.general (#16459) next »