Right.
(SELECT col1, col2, col3, col4 FROM table1, table2 WHERE table1.col1 = table2.col1 and table1.col2 = 1 ORDER BY col3 DESC LIMIT 5) UNION (SELECT col1, col2, col3, col4 FROM table1, table2 WHERE table1.col1 = table2.col1 and table1.col2 = 2 ORDER BY col3 DESC LIMIT 5) UNION (SELECT col1, col2, col3, col4 FROM table1, table2 WHERE table1.col1 = table2.col1 and table1.col2 = 3 ORDER BY col3 DESC LIMIT 5) ORDER BY col3 DESC;
should work. Notice that you can reorder the results after the UNIONs, if you want, with a final ORDER BY clause. UNION is available in MySQL 4.0.0 and up.
Michael
[EMAIL PROTECTED] wrote:
I believe you need to combine the results of 3 separate queries (each with a limit of 5) into a temp table and respond with the contents of the table you built. If I read this correctly (http://dev.mysql.com/doc/mysql/en/UNION.html) you could do the same thing with a UNION query and skip the temp table step (MySQL does it for you). But you must have be using a version that supports UNION queries.
Each piece-wise query must have it's own LIMIT constraint in order to apply the limit to each value you are querying on. Using either method you could even want 10 of #1 but only 5 of #2 and only 3 of #3 and still make it work.
Shawn Green Database Administrator Unimin Corporation - Spruce Pine
-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]