NYCPHP Meetup

NYPHP.org

[nycphp-talk] PHP array_unique vs. SQL DISTINCT

David Krings ramons at gmx.net
Sun Jun 3 13:26:32 EDT 2007


Hi!

Which one is faster: PHP array_unique or SQL DISTINCT ?

I learned about the DISTINCT key word for SQL some time ago and remember 
that pro developers always told me that SQL is faster than code.
I tested a slightly complex select query across three tables and used 
DISTINCT. The tables have each less than 1,000 records, two of the three 
have only about 600 rows. I let the query run for at least half an hour 
before I hit the reset button (PHP would have timed out much earlier). I 
then tested again but without any sorting, but that didn't make any 
difference. I then googled and some claim that DISTINCT isn't all that 
speedy.

Any advice is greatly appreciated.

David




More information about the talk mailing list