MySQL Forums
Forum List  »  Newbie

Re: Out of memory for query
Posted by: Jay Pipes
Date: June 20, 2005 07:55AM

a) The LIMIT clause is meaningless in an EXISTS subquery. EXISTS returns true as soon as one row is found.

b) You could use a join:

SELECT COUNT(*) FROM tbl1 f1
INNER JOIN (
SELECT col1, col2, MAX(col3) AS col3
FROM tbl1
GROUP BY col1, col2
) AS f2
ON f1.col1 = f2.col1
AND f1.col2 = f2.col2
AND f1.col3 = f2.col3;

If you're going to be doing this repeatedly on a table with 8M rows, I'd recommend first making an index on (col1, col2, col3)

Cheers,

Jay

Jay Pipes
Community Relations Manager, North America, MySQL Inc.

Got Cluster? http://www.mysql.com/cluster
Personal: http://jpipes.com

Options: ReplyQuote


Subject
Written By
Posted
June 20, 2005 07:00AM
Re: Out of memory for query
June 20, 2005 07:55AM
June 20, 2005 10:24AM
June 20, 2005 11:15AM
June 20, 2005 04:29PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.