Re: combining the results of mysql query and finding the unique tuples in php

From: Date: Fri, 07 Jan 2011 14:46:24 +0000
Subject: Re: combining the results of mysql query and finding the unique tuples in php
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-47612@lists.php.net to get a copy of this message
On 1/7/2011 12:10 AM, Fahim M wrote:
Hi I have a certain number of mysql tables(relation), say 50, some of them having 5 fields and some with 6 fields. a particular search item may be found in multiple tables with multiple rows. I am using a loop to find all those. My problem is I want to first combine all those results and then find all the unique entries. (the query results may overlap). What is the best way to do it? If you're looking for unique results, do a UNION query for all the tables. You'll need to add a dummy field for the 5-field tables, and make sure the field names are the same (use <oldfieldname> AS <newfieldname> to make sure everything ends up the correct result column). UNION queries automatically remove duplicates.
Toby

« previous php.db (#47612) next »