Re: DB_OB DISTINCT

From: Date: Wed, 10 Dec 2003 02:51:05 +0000
Subject: Re: DB_OB DISTINCT
References: 1  Groups: php.pear.general php.pear.general 
Request: Send a blank email to pear-general+get-9442@lists.php.net to get a copy of this message
Daniel Kopp wrote:
Hi! I am looking for a way to fetch information from 3 tables: Table a: Contains information about a person: Pid & some data Table b: Is a connection to another table Pid & another ID of another table Table c: Is also a connection to another table Pid & another ID of another table Now I want to join table b and c to a: In DB_OBJECTS: $a->selectAs(); $a->joinAdd($b); $a->joinAdd($c); no selectAs needed as I don't need the information from the other tables - just want to be able to set where-clauses Unfortunately I get the rows from table a more than once if they have more than 1 matching row in table b or c. A "DISTINCT" would cut it down to what I really need. But how can I set Distinct in DB_OBJECTS?
the only way to do it is a) a query() b) sneak it in as part of the selectAdd() - eg. $a->selectAdd('DISTINCT 1 as __tmp");
I explained the whole story because I think there might be a better way to do it than DISTINCT.
Im not sure if $a->joinAdd($b,'LEFT'); may help.
I know - I could just use $a->query() but it is for a search engine which has lots of possible WHERE clauses and that would be just very easy with DB_OBJECTS ... Is it possible to get the generated query before fetching anything? Then I would only need to add the DISTINCT at the right position (Which would be simply replacing "SELECT" by "SELECT DISTINCT").
cant think of any smart way of doing this at present.. Regards Alan
Thanks for your thoughts! Regards Daniel
-- Can you help out? Need Consulting Services or Know of a Job? http://www.akbkhome.com

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