DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Benoit has posted 48 posts at DZone. View Full User Profile

Assign A Rank To Each Row Of A Result

09.23.2009
| 2022 views |
  • submit to reddit
        Assign a rank to each row of a result

SELECT (
	SELECT COUNT(id) FROM table t2
	WHERE t2.title <= t1.title 
	) AS rank , t1.*
FROM table t1
ORDER BY t1.title

<a href="http://www.ab-d.fr/">Source: </a><a href="http://www.ab-d.fr/date/2009-09-23/">Comment attribuer un rang aux lignes d'un résultat en MySQL ? ( sql ) </a><a href="http://www.vytafitnesssports.fr/">(vyta)</a>