FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


statement MySQL question





saberlivre
I have in my database table with three columns: 'day', 'name' and 'address'. I want to get the rows grouped by 'day', but limited to only 5 results for each day. What is the best (optimal) way to do this?

Sorry for my bad english.
rvec
Try reading this:
http://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/

If you're any good at mysql I'd suggest reading through the article and the comments, if you just want it to work (and don't mind it being a second slower than optimal) just use the first "Select the top N rows from each group" option.
macky
saberlivre wrote:
I have in my database table with three columns: 'day', 'name' and 'address'. I want to get the rows grouped by 'day', but limited to only 5 results for each day. What is the best (optimal) way to do this?

Sorry for my bad english.


Do you mean grouped them in column day and then fetch them limited to each day current date?

As far as i know, if i'm not mistaken, MySQL cannot perform this job alone. You can use PHP for giving certain conditions.

Example use GROUP BY and then LIMIT to your SQL statement/syntax and then while fetching do some if else condition coz you may want still to validate that the least 5 result yesterday will never fetched out.
gueda
saberlivre wrote:
I have in my database table with three columns: 'day', 'name' and 'address'. I want to get the rows grouped by 'day', but limited to only 5 results for each day. What is the best (optimal) way to do this?

Sorry for my bad english.


How do you want to get it? I means: what programming are you using? Php, asp etc?
saberlivre
gueda
I use perl but I have noticed that the required modules are not installed.

rvec and macky
Thanks, I think the article mentioned by you was enlightening.

Sorry for my English.
Related topics
PHP/MySQL question
n00b mySQL question :D
quick mysql question
Mysql question!
Homosexuality, is it biologically natural?
The last foolish PHP/MySQL Question of the Year....
MySQL Question
mySQL question....
newbie MySQL question
PHP MySQL Question
mySQL question
mySQL question N2 - Indexing
Question about the 'Gap'
Newbie PHP/MySQL question
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.