You are here: Re: Optimizing SQL queries « PHP Programming Language « IT news, forums, messages
Re: Optimizing SQL queries

Posted by Ridge Burner on 04/11/06 16:58

"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)

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация