<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: SQL: Ranking without self join</title>
	<atom:link href="http://code.openark.org/blog/mysql/sql-ranking-without-self-join/feed" rel="self" type="application/rss+xml" />
	<link>http://code.openark.org/blog/mysql/sql-ranking-without-self-join</link>
	<description>Blog by Shlomi Noach</description>
	<lastBuildDate>Thu, 09 Sep 2010 18:52:58 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: links for 2010-06-25 &#124; Digitalistic - Mashup or die trying</title>
		<link>http://code.openark.org/blog/mysql/sql-ranking-without-self-join/comment-page-1#comment-15133</link>
		<dc:creator>links for 2010-06-25 &#124; Digitalistic - Mashup or die trying</dc:creator>
		<pubDate>Fri, 25 Jun 2010 14:03:51 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=1293#comment-15133</guid>
		<description>[...] SQL: Ranking without self join &#124; code.openark.org (tags: sql join ranking optimization mysql) [...]</description>
		<content:encoded><![CDATA[<p>[...] SQL: Ranking without self join | code.openark.org (tags: sql join ranking optimization mysql) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shlomi</title>
		<link>http://code.openark.org/blog/mysql/sql-ranking-without-self-join/comment-page-1#comment-10147</link>
		<dc:creator>shlomi</dc:creator>
		<pubDate>Tue, 02 Feb 2010 19:53:03 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=1293#comment-10147</guid>
		<description>George,

Reset as in @c := 0, nothing fancy...</description>
		<content:encoded><![CDATA[<p>George,</p>
<p>Reset as in @c := 0, nothing fancy&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: George</title>
		<link>http://code.openark.org/blog/mysql/sql-ranking-without-self-join/comment-page-1#comment-10146</link>
		<dc:creator>George</dc:creator>
		<pubDate>Tue, 02 Feb 2010 19:38:16 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=1293#comment-10146</guid>
		<description>Hi Shlomi,

This piece of gold has already helped me immensely, thanks.

As per #18, how would I reset the other variable? I cannot seem to find anything on mysql.com</description>
		<content:encoded><![CDATA[<p>Hi Shlomi,</p>
<p>This piece of gold has already helped me immensely, thanks.</p>
<p>As per #18, how would I reset the other variable? I cannot seem to find anything on mysql.com</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MySQL: Another Ranking trick &#171; JZ Talk Blogger</title>
		<link>http://code.openark.org/blog/mysql/sql-ranking-without-self-join/comment-page-1#comment-9602</link>
		<dc:creator>MySQL: Another Ranking trick &#171; JZ Talk Blogger</dc:creator>
		<pubDate>Thu, 21 Jan 2010 07:28:32 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=1293#comment-9602</guid>
		<description>[...] Another Ranking trick I just read SQL: Ranking without self join, in which Shlomi Noach shares a nice MySQL-specific trick based on user-defined variables to [...]</description>
		<content:encoded><![CDATA[<p>[...] Another Ranking trick I just read SQL: Ranking without self join, in which Shlomi Noach shares a nice MySQL-specific trick based on user-defined variables to [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shlomi</title>
		<link>http://code.openark.org/blog/mysql/sql-ranking-without-self-join/comment-page-1#comment-9379</link>
		<dc:creator>shlomi</dc:creator>
		<pubDate>Thu, 14 Jan 2010 18:59:41 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=1293#comment-9379</guid>
		<description>@Pau

Very nice! Thanks for sharing</description>
		<content:encoded><![CDATA[<p>@Pau</p>
<p>Very nice! Thanks for sharing</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pau Sanchez</title>
		<link>http://code.openark.org/blog/mysql/sql-ranking-without-self-join/comment-page-1#comment-9337</link>
		<dc:creator>Pau Sanchez</dc:creator>
		<pubDate>Wed, 13 Jan 2010 16:27:08 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=1293#comment-9337</guid>
		<description>Fantastic solution!

I was looking for a solution and it come up after looking to this post ;)

My problem was having a sort_index field used to sort some elements in a particular order.

The thing is that the indexes were not consecutive, and that caused some trouble for some tasks I&#039;m not going to talk about.

Thanks to your solution I came up with:

SET @pos := 0;
UPDATE sort_example 
      SET sort_index = (SELECT @pos := @pos+1)
ORDER BY sort_index ASC

So if before running this code the sort_indexes of several rows were:
1, 32, 34, 58, 99, 1028, 9982

After running the update they turned into:
1, 2, 3, 4, 5, 6, 7

Just wanted to share, maybe it can be useful to someone else.

Thanks!</description>
		<content:encoded><![CDATA[<p>Fantastic solution!</p>
<p>I was looking for a solution and it come up after looking to this post <img src='http://code.openark.org/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>My problem was having a sort_index field used to sort some elements in a particular order.</p>
<p>The thing is that the indexes were not consecutive, and that caused some trouble for some tasks I&#8217;m not going to talk about.</p>
<p>Thanks to your solution I came up with:</p>
<p>SET @pos := 0;<br />
UPDATE sort_example<br />
      SET sort_index = (SELECT @pos := @pos+1)<br />
ORDER BY sort_index ASC</p>
<p>So if before running this code the sort_indexes of several rows were:<br />
1, 32, 34, 58, 99, 1028, 9982</p>
<p>After running the update they turned into:<br />
1, 2, 3, 4, 5, 6, 7</p>
<p>Just wanted to share, maybe it can be useful to someone else.</p>
<p>Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roland Bouman</title>
		<link>http://code.openark.org/blog/mysql/sql-ranking-without-self-join/comment-page-1#comment-6030</link>
		<dc:creator>Roland Bouman</dc:creator>
		<pubDate>Wed, 04 Nov 2009 06:59:03 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=1293#comment-6030</guid>
		<description>Hi Sergio,

post your table definition, some 20 rows of sample data that illustrate the desired result.</description>
		<content:encoded><![CDATA[<p>Hi Sergio,</p>
<p>post your table definition, some 20 rows of sample data that illustrate the desired result.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Toby</title>
		<link>http://code.openark.org/blog/mysql/sql-ranking-without-self-join/comment-page-1#comment-6020</link>
		<dc:creator>Toby</dc:creator>
		<pubDate>Wed, 04 Nov 2009 02:24:31 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=1293#comment-6020</guid>
		<description>Sergio,
You could always just use the self join approach, which makes your scenarios simple.</description>
		<content:encoded><![CDATA[<p>Sergio,<br />
You could always just use the self join approach, which makes your scenarios simple.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sergio</title>
		<link>http://code.openark.org/blog/mysql/sql-ranking-without-self-join/comment-page-1#comment-6019</link>
		<dc:creator>sergio</dc:creator>
		<pubDate>Wed, 04 Nov 2009 01:56:32 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=1293#comment-6019</guid>
		<description>Hello again, I have tried what you said but it doesnt seem to work, can you provide a little more insigth really getting fustrated. Also as an added question to add to the previous question on top of the test_ids for multiple tests stored in the same table, what if another column was added with bonus_score which rank is determined first by the regular score and if equal, then the bonus score is used to determine the ranks? I really appricate any insight you can provide as this is very frustrating to me.</description>
		<content:encoded><![CDATA[<p>Hello again, I have tried what you said but it doesnt seem to work, can you provide a little more insigth really getting fustrated. Also as an added question to add to the previous question on top of the test_ids for multiple tests stored in the same table, what if another column was added with bonus_score which rank is determined first by the regular score and if equal, then the bonus score is used to determine the ranks? I really appricate any insight you can provide as this is very frustrating to me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shlomi</title>
		<link>http://code.openark.org/blog/mysql/sql-ranking-without-self-join/comment-page-1#comment-5964</link>
		<dc:creator>shlomi</dc:creator>
		<pubDate>Tue, 03 Nov 2009 05:36:54 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=1293#comment-5964</guid>
		<description>@sergio
Yes, it is possible; you would need to maintain two sets of variables ; the primary being the test_id, the secondary being for the score.
Whenever the test id changes, you reset the score variables.
you first ORDER BY test_id DESC, SCORE DESC.</description>
		<content:encoded><![CDATA[<p>@sergio<br />
Yes, it is possible; you would need to maintain two sets of variables ; the primary being the test_id, the secondary being for the score.<br />
Whenever the test id changes, you reset the score variables.<br />
you first ORDER BY test_id DESC, SCORE DESC.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
