Comments on: How to number rows in MySQL http://www.xaprb.com/blog/2006/12/02/how-to-number-rows-in-mysql/ Stay curious! Thu, 02 May 2013 12:36:53 +0000 hourly 1 http://wordpress.org/?v=3.5.1 By: John Lynn http://www.xaprb.com/blog/2006/12/02/how-to-number-rows-in-mysql/#comment-19639 John Lynn Sat, 17 Sep 2011 21:58:49 +0000 http://www.xaprb.com/blog/?p=265#comment-19639 Great tip! It doesn’t work if “fruits” (the table you’re selecting from) is a view, it seems. Using MySQL 5.5

Thanks…

]]>
By: Ozlem http://www.xaprb.com/blog/2006/12/02/how-to-number-rows-in-mysql/#comment-18934 Ozlem Mon, 22 Nov 2010 22:38:27 +0000 http://www.xaprb.com/blog/?p=265#comment-18934 Hi, this is a great solution however it does not work from php. I mean when I run the query through php it does not gather any result. it does not recognize first 2 lines of code, set functions…Any suggestion is appreciated.?Thanks…Ozlem.

set @countT = 0;
set @rowCount = 0;

SELECT MQ2.period_id, MQ2.lt_id, MQ2.period_name, MQ2.min_stay, MQ2.fromDate, MQ2.toDate, MQ2.nightly_rate, MQ2.periodDays,
MQ2.totalDays, MQ2.fixed_rate, @countT as periodDaysTotal, @rowCount as rowsTotal ,

IF ((@rowCount=1),

IF((MQ2.periodDays <= (SELECT MAX(night_of_stay) FROM lt_hrules WHERE period_id=MQ2.period_id AND lt_id=MQ2.lt_id)),

IF(MQ2.periodDays IN (SELECT night_of_stay FROM lt_hrules WHERE period_id=MQ2.period_id AND lt_id=MQ2.lt_id),
(SELECT fixed_rate FROM lt_hrules WHERE period_id = MQ2.period_id AND lt_id = MQ2.lt_id AND night_of_stay = MQ2.periodDays ),
(SELECT fixed_rate FROM lt_hrules WHERE period_id = MQ2.period_id AND lt_id = MQ2.lt_id AND night_of_stay =
(SELECT MAX(night_of_stay) from lt_hrules WHERE period_id = MQ2.period_id AND lt_id = MQ2.lt_id))
),

(MQ2.nightly_rate * MQ2.periodDays)) ,

(MQ2.nightly_rate * MQ2.periodDays)
) as price
FROM

]]>
By: Zilus http://www.xaprb.com/blog/2006/12/02/how-to-number-rows-in-mysql/#comment-18489 Zilus Thu, 08 Jul 2010 22:26:03 +0000 http://www.xaprb.com/blog/?p=265#comment-18489 Awsome! I use this in a Query to order my results, sort of “x / x/” I mean, like $num / $total

I’ll post my code and give you credits!

Thanks!

]]>
By: Nico http://www.xaprb.com/blog/2006/12/02/how-to-number-rows-in-mysql/#comment-18479 Nico Tue, 06 Jul 2010 10:46:55 +0000 http://www.xaprb.com/blog/?p=265#comment-18479 Thank you for sharing!

The use of an order by clause does mix up the row numbers for me. In case you need an order by you can use a subquery for the ordering and apply the order number in the outer select…

]]>
By: 也谈MySQL中实现ROWNUM - 轶侠的网上小窝 http://www.xaprb.com/blog/2006/12/02/how-to-number-rows-in-mysql/#comment-16611 也谈MySQL中实现ROWNUM - 轶侠的网上小窝 Mon, 29 Jun 2009 02:15:51 +0000 http://www.xaprb.com/blog/?p=265#comment-16611 [...] How to number rows in MySQL [...]

]]>