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

Jay K <[EMAIL PROTECTED]> wrote on 10/14/2004 01:59:47 AM:

> Yes. I want to retrieve 5 of each.
> 
> If I put LIMIT 5, the entire query retrieves only 5
> for table1.col2 with value of 1 because 1 is the first
> in the IN (1,2,3) clause.
> 
> If I put LIMIT 15, the query returns 15 rows same as
> above instead 5 for each 1, 2, and 3 values. This is
> because there are more than 15 rows in the table with
> value "1" in table1.col2. The query will start with
> table1.col2 with value of "2" only when the number of
> rows with the value ("1") are exhausted and the limit
> is more than the count.
> 
> ~Jay
> 
> --- Michael Stassen <[EMAIL PROTECTED]>
> wrote:
> 
> > Why do you think it doesn't work with LIMIT?  Do you
> > want 5 of each?
> > 
> > Michael
> > 
> > Jay K wrote:
> > 
> > > Hi,
> > > 
> > > I have multiple queries like this:
> > > 
> > > SELECT col1, col2, col3, col4 FROM table1, table2
> > > where table1.col1 = table2.col1 and table1.col2 =
> > 1
> > > ORDER BY col3 desc LIMIT 5
> > > 
> > > and
> > > 
> > > SELECT col1, col2, col3, col4 FROM table1, table2
> > > where table1.col1 = table2.col1 and table1.col2 =
> > 2
> > > ORDER BY col3 desc LIMIT 5
> > > 
> > > The only difference is in the WHERE clause
> > table1.col2
> > > = x.
> > > 
> > > I would like to have one statement instead of
> > multiple
> > > statements and though about using IN clause like:
> > > 
> > > SELECT col1, col2, col3, col4 FROM table1, table2
> > > where table1.col1 = table2.col1 and table1.col2 IN
> > > (1,2,3) ORDER BY col3 desc LIMIT 5
> > > 
> > > It works without LIMIT, but I need to use the
> > LIMIT.
> > > 
> > > Any help is appreciated.
> > > 
> > > Thanks in advance,
> > > Jay
> > > 
> > > 
> > > 
> > > _______________________________
> > > Do you Yahoo!?
> > > Declare Yourself - Register online to vote today!
> > > http://vote.yahoo.com
> > > 
> > 
> > -- 
> > MySQL General Mailing List
> > For list archives: http://lists.mysql.com/mysql
> > To unsubscribe: 
> >
> http://lists.mysql.com/[EMAIL PROTECTED]
> > 
> > 
> 
> 
> 
> 
> __________________________________
> Do you Yahoo!?
> Yahoo! Mail Address AutoComplete - You start. We finish.
> http://promotions.yahoo.com/new_mail 
> 
> -- 
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]
> 

Reply via email to