NYCPHP Meetup

NYPHP.org

[nycphp-talk] MySQL help

Andrew Yochum andrew at digitalpulp.com
Thu Oct 21 17:49:29 EDT 2004


On Thu, Oct 21, 2004 at 05:41:27PM -0400, Stephen Musgrave wrote:
> So, I thought this query would be easy, but I've spent the better part 
> of an afternoon on it.  To put it mildly:  it's very slow.  Any tips on 
> how i might speed it up would be greatly appreciated.
> 
> SELECT
> 	a.column1
> 	COUNT(DISTINCT c.column1) as column1_count
> FROM
> 	table1 a,
> 	table2 b,
> 	table3 d,
> 	table4 h
> WHERE
> 	a.column2 = 1 AND a.column3 = 1
> 	AND (c.column3 = a.column3 AND c.column2 = a.column2)
> 	AND (d.column3 = a.column3 AND d.column2 = a.column2)
> 	AND (h.column3 = a.column3 AND h.column2 = a.column2)
> GROUP BY
> 	a. column3
> HAVING
> 	(column1_count >= 2)

Do you have indexes on column2 and column3 on each of the tables?

The output of explain would probably be helpful.  Just put the word
"explain" before the select.



More information about the talk mailing list