By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,557 Members | 1,406 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,557 IT Pros & Developers. It's quick & easy.

Ranking system

P: 1
Hi,
I have a query that extracts the last 7 records from a database based on its criteria and have it ordered by its date. What i want to do is add a column in the select statement and put in the numbers from 1 to 7 into the column in this added column.

I'm using the Space(1) as Number function but i am wondering how do I put 1 to 7 in the table. Its pretty much like a ranking system.

Using PHP is not an option for me. Even something like a line counter or a result set counter would work.

Any help would be greatly appreciated.
reagrds,
Enpsycho.
Feb 22 '07 #1
Share this Question
Share on Google+
1 Reply


ronverdonk
Expert 2.5K+
P: 4,258
Since MySQL does not have explicit row numbering facilites, you have to use a counter. Like the following example shows:

Expand|Select|Wrap|Line Numbers
  1. SET @n=0;
  2. SELECT @n := @n+1 AS No, fielda, fieldb from table;
  3.  
Ronald :cool:
Feb 23 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.