|
Posted by Chuck Anderson on 04/11/06 21:11
Ridge Burner wrote:
>"Justin" <legrice@nix2spam.i4free.co.nz> wrote in message
>news:443b11ec$1@clear.net.nz...
>
>
>>Google search gave me the following example.
>>
>>SQL Server:
>>SELECT TOP 10 product, descr, email
>>FROM products
>>
>>ORACLE:
>>SELECT product, descr, email
>>FROM products
>>WHERE ROWNUM <= 10
>>
>>MySQL:
>>SELECT product, descr, email
>>FROM products
>>LIMIT 10
>>
>>Google is yer friend!!!
>>
>>
>
>Yes Google is my friend! However, Google is not my smart friend! Google's
>answer only returns 10 rows, no matter how many unique users are in table.
>I need the first three rows for EACH UNIQUE user in table, so if I have 5
>users, I want 15 rows returned, 25 users gives me 75 rows.
>
>Basically I am trying to combine the following queries into one query:
>
>1) SELECT * FROM myTable WHERE user='JOE' LIMIT 3;
>2) SELECT * FROM myTable WHERE user='FRED' LIMIT 3;
>3) SELECT * FROM myTable WHERE user='JIMBOB' LIMIT 3;
>4) SELECT * FROM myTable WHERE user='MARY' LIMIT 3;
>5) SELECT * FROM myTable WHERE user='ELIZABETH' LIMIT 3;
>
>I was hoping for a more manageable query statement, kinda like:
>
>SELECT first 3 items for each UNIQUE user ORDER BY date_added ASC
>
>Right now I can either hard code the queries for each user (really bad idea)
>or I can query for list of unique names in table, store in array and loop
>thru those (better idea)
>
>
>
>
Try asking in comp.databases.mysql.
--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
*****************************
Navigation:
[Reply to this message]
|