<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: How to number rows in MySQL</title>
	<link>http://www.xaprb.com/blog/2006/12/02/how-to-number-rows-in-mysql/</link>
	<description>Stay curious!</description>
	<pubDate>Wed, 09 Jul 2008 03:38:14 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.2</generator>

	<item>
		<title>By: Allison</title>
		<link>http://www.xaprb.com/blog/2006/12/02/how-to-number-rows-in-mysql/#comment-14556</link>
		<author>Allison</author>
		<pubDate>Wed, 14 May 2008 14:28:07 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/12/02/how-to-number-rows-in-mysql/#comment-14556</guid>
		<description>Thanks, Unomi! Your solution works great for me... I was looking for an alternative to SQL Server 2005's row_number() function.</description>
		<content:encoded><![CDATA[<p>Thanks, Unomi! Your solution works great for me&#8230; I was looking for an alternative to SQL Server 2005&#8217;s row_number() function.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tadwook</title>
		<link>http://www.xaprb.com/blog/2006/12/02/how-to-number-rows-in-mysql/#comment-14260</link>
		<author>tadwook</author>
		<pubDate>Fri, 29 Feb 2008 00:16:47 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/12/02/how-to-number-rows-in-mysql/#comment-14260</guid>
		<description>thanks rackoon -- THIS METHOD DOES NOT WORK WITH order by -- just FYI</description>
		<content:encoded><![CDATA[<p>thanks rackoon &#8212; THIS METHOD DOES NOT WORK WITH order by &#8212; just FYI</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Xaprb</title>
		<link>http://www.xaprb.com/blog/2006/12/02/how-to-number-rows-in-mysql/#comment-13507</link>
		<author>Xaprb</author>
		<pubDate>Wed, 10 Oct 2007 01:46:14 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/12/02/how-to-number-rows-in-mysql/#comment-13507</guid>
		<description>The manual is vague and inaccurate about this point.  You have to read the source code and learn how the MySQL query executioner (yes, it's actually called that!) works.</description>
		<content:encoded><![CDATA[<p>The manual is vague and inaccurate about this point.  You have to read the source code and learn how the MySQL query executioner (yes, it&#8217;s actually called that!) works.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rackoon</title>
		<link>http://www.xaprb.com/blog/2006/12/02/how-to-number-rows-in-mysql/#comment-13506</link>
		<author>rackoon</author>
		<pubDate>Tue, 09 Oct 2007 21:37:29 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/12/02/how-to-number-rows-in-mysql/#comment-13506</guid>
		<description>If I'm not mistaken, there is no guarantee that this method works. In the mysql-manual it says:

---SNIP---

The order of evaluation for user variables is undefined and may change based on the elements contained within a given query. In SELECT @a, @a := @a 1 ..., you might think that MySQL will evaluate @a first and then do an assignment second, but changing the query (for example, by adding a GROUP BY, HAVING, or ORDER BY clause) may change the order of evaluation.

The general rule is never to assign a value to a user variable in one part of a statement and use the same variable in some other part of the same statement. You might get the results you expect, but this is not guaranteed.

---SNIP---

So how do you know that in your first example "if(@type = type, @num   1, 1)" is evaluated before you reassign @type via "@type := type"?</description>
		<content:encoded><![CDATA[<p>If I&#8217;m not mistaken, there is no guarantee that this method works. In the mysql-manual it says:</p>
<p>&#8212;SNIP&#8212;</p>
<p>The order of evaluation for user variables is undefined and may change based on the elements contained within a given query. In SELECT @a, @a := @a 1 &#8230;, you might think that MySQL will evaluate @a first and then do an assignment second, but changing the query (for example, by adding a GROUP BY, HAVING, or ORDER BY clause) may change the order of evaluation.</p>
<p>The general rule is never to assign a value to a user variable in one part of a statement and use the same variable in some other part of the same statement. You might get the results you expect, but this is not guaranteed.</p>
<p>&#8212;SNIP&#8212;</p>
<p>So how do you know that in your first example &#8220;if(@type = type, @num   1, 1)&#8221; is evaluated before you reassign @type via &#8220;@type := type&#8221;?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Xaprb</title>
		<link>http://www.xaprb.com/blog/2006/12/02/how-to-number-rows-in-mysql/#comment-12990</link>
		<author>Xaprb</author>
		<pubDate>Sat, 04 Aug 2007 11:07:57 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/12/02/how-to-number-rows-in-mysql/#comment-12990</guid>
		<description>The simplest way is to make a multiple-column primary key on (type, variety, ai) where ai is an auto_increment integer.  This only works on MyISAM, though.</description>
		<content:encoded><![CDATA[<p>The simplest way is to make a multiple-column primary key on (type, variety, ai) where ai is an auto_increment integer.  This only works on MyISAM, though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick T.</title>
		<link>http://www.xaprb.com/blog/2006/12/02/how-to-number-rows-in-mysql/#comment-12973</link>
		<author>Nick T.</author>
		<pubDate>Sat, 04 Aug 2007 07:07:04 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/12/02/how-to-number-rows-in-mysql/#comment-12973</guid>
		<description>I'm a new MySQL/PHP user, so please bear with me.  The information you provided, Xaprb, is excellent.  But is there a way I can make the row_number column a permanent column in my database instead of just output?

I have a table very similar to that of "fruits", with several broad "types" and specific "varieties" within those "types".  I need to add another column numbering these types but the table is just too big to do it by hand.  The solution you mentioned above is great for output, but how can I add the column into the permanent table itself?

I tried to make a MySQL dump file of the query you gave above, and then import that into my table using PHPMyAdmin, but I kept getting errors.  Is there another way?</description>
		<content:encoded><![CDATA[<p>I&#8217;m a new MySQL/PHP user, so please bear with me.  The information you provided, Xaprb, is excellent.  But is there a way I can make the row_number column a permanent column in my database instead of just output?</p>
<p>I have a table very similar to that of &#8220;fruits&#8221;, with several broad &#8220;types&#8221; and specific &#8220;varieties&#8221; within those &#8220;types&#8221;.  I need to add another column numbering these types but the table is just too big to do it by hand.  The solution you mentioned above is great for output, but how can I add the column into the permanent table itself?</p>
<p>I tried to make a MySQL dump file of the query you gave above, and then import that into my table using PHPMyAdmin, but I kept getting errors.  Is there another way?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Xaprb</title>
		<link>http://www.xaprb.com/blog/2006/12/02/how-to-number-rows-in-mysql/#comment-12402</link>
		<author>Xaprb</author>
		<pubDate>Thu, 19 Jul 2007 10:42:09 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/12/02/how-to-number-rows-in-mysql/#comment-12402</guid>
		<description>You need to read two of my other articles: the "next" article linked from the top of this page, on finding the first row per group, and this one about &lt;a href="/blog/2006/03/11/many-to-one-problems-in-sql/" rel="nofollow"&gt;incorrect GROUP BY&lt;/a&gt;, which you are doing and is causing you trouble.</description>
		<content:encoded><![CDATA[<p>You need to read two of my other articles: the &#8220;next&#8221; article linked from the top of this page, on finding the first row per group, and this one about <a href="/blog/2006/03/11/many-to-one-problems-in-sql/" rel="nofollow">incorrect GROUP BY</a>, which you are doing and is causing you trouble.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rafael Vale</title>
		<link>http://www.xaprb.com/blog/2006/12/02/how-to-number-rows-in-mysql/#comment-12392</link>
		<author>Rafael Vale</author>
		<pubDate>Wed, 18 Jul 2007 18:46:05 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/12/02/how-to-number-rows-in-mysql/#comment-12392</guid>
		<description>Yo there!
Your posts helps me very much, thank u for that!
I have a little problem and probably somebody here can help me!
I need to select the entries of a table. But i want only the MAX(id) from each product_id of that table. 
i'm trying:
SELECT max(id), id_pit, id_atend FROM table GROUP BY id_pit

but the result is the MAX id with the id_atend from another id.

How can i do it?

Thanks for atention!</description>
		<content:encoded><![CDATA[<p>Yo there!<br />
Your posts helps me very much, thank u for that!<br />
I have a little problem and probably somebody here can help me!<br />
I need to select the entries of a table. But i want only the MAX(id) from each product_id of that table.<br />
i&#8217;m trying:<br />
SELECT max(id), id_pit, id_atend FROM table GROUP BY id_pit</p>
<p>but the result is the MAX id with the id_atend from another id.</p>
<p>How can i do it?</p>
<p>Thanks for atention!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.xaprb.com/blog/2006/12/02/how-to-number-rows-in-mysql/#comment-11470</link>
		<author>Alex</author>
		<pubDate>Mon, 11 Jun 2007 00:08:16 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/12/02/how-to-number-rows-in-mysql/#comment-11470</guid>
		<description>Anyone have a solution for SQLite? It doesn't have user-defined variables, sadly.</description>
		<content:encoded><![CDATA[<p>Anyone have a solution for SQLite? It doesn&#8217;t have user-defined variables, sadly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Xaprb</title>
		<link>http://www.xaprb.com/blog/2006/12/02/how-to-number-rows-in-mysql/#comment-5659</link>
		<author>Xaprb</author>
		<pubDate>Wed, 11 Apr 2007 18:22:00 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/12/02/how-to-number-rows-in-mysql/#comment-5659</guid>
		<description>&lt;p&gt;That's a great solution.&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>That&#8217;s a great solution.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
