On Wed, 2009-02-04 at 14:42 -0800, PHP wrote:
> Hi all,
> I am seeking some knowledge, hopefully I explain this right.
>
> I am wondering what you think is faster.
>
> Say you have 1000 records from 2 different tables that you need to get from a
> MySQL database.
> A simple table will be displayed for each record, the second table contains
> related info for each record in table 1.
>
> Is if faster to just read all the records from both tables into two arrays,
> then use php to go through the array for table 1 and figure out what records
> from table 2 are related.
>
> Or, you dump all the data in table 1 into an array, then as you go through
> each record you make a database query to table 2.
>
>
>
>
> PS:
> I know I can use a join, but I find anytime I use a join, the database query
> is extremely slow, I have tried it for each version of mysql and php for the
> last few years. The delay difference is in the order of 100x slower or more.
Grab records from table 1... build a list of IDs to match in table 2.
Use an IN clause. 2 queries and no joins as you requested.
SELECT * from foo_table AS FOO where "something something";
SELECT * from fee_table AS FEE where foo_id IN ( list, of, ids );
You REALLY don't want to do a query for every row matched in the first
query.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php