﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by Revenant  / RANK() returns consecutive integers / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Mon, 20 May 2013 20:36:31 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: RANK() returns consecutive integers</title><link>http://www.sqlservercentral.com/Forums/Topic1043461-2671-1.aspx</link><description>The RANK Function is a pretty interesting topic and a great pick.  Below is an great example too using the AdventureWorks200R2 database.URL: http://msdn.microsoft.com/en-us/library/ms189798.aspxThank you for the question.</description><pubDate>Fri, 02 Mar 2012 15:47:41 GMT</pubDate><dc:creator>zymos</dc:creator></item><item><title>RE: RANK() returns consecutive integers</title><link>http://www.sqlservercentral.com/Forums/Topic1043461-2671-1.aspx</link><description>I knew that Rank() skips the number if there is a tie but thought it's still consecutive number in a sense next available int number.</description><pubDate>Tue, 18 Jan 2011 06:03:03 GMT</pubDate><dc:creator>Dhruvesh Shah</dc:creator></item><item><title>RE: RANK() returns consecutive integers</title><link>http://www.sqlservercentral.com/Forums/Topic1043461-2671-1.aspx</link><description>[quote][b]toddasd (1/6/2011)[/b][hr]Is it considered cheating that I went to the BOL before answering the question and read "If two or more rows tie for a rank, each tied rows receives the same rank."?[/quote]"Cheating" implies that this is a test - which it isn't. QotD is designed to do just this - get you looking into areas of SQL that you might not have been aware of. If you researched something, and learned from it, then mission accomplished.</description><pubDate>Fri, 07 Jan 2011 04:30:17 GMT</pubDate><dc:creator>WayneS</dc:creator></item><item><title>RE: RANK() returns consecutive integers</title><link>http://www.sqlservercentral.com/Forums/Topic1043461-2671-1.aspx</link><description>[quote][b]Koen (da-zero) (1/6/2011)[/b][hr][quote][b]toddasd (1/6/2011)[/b][hr]Is it considered cheating that I went to the BOL before answering the question and read "If two or more rows tie for a rank, each tied rows receives the same rank."?[/quote]I don't consider doing research and learning from it cheating.I'm not going to memorize every feature, trace flag, syntax, dmv of SQL Server. If I need something, I'll look it up :-)[/quote]I agree! It's impossible to remember details of every command of every language.:-)</description><pubDate>Fri, 07 Jan 2011 01:26:51 GMT</pubDate><dc:creator>Carlo Romagnano</dc:creator></item><item><title>RE: RANK() returns consecutive integers</title><link>http://www.sqlservercentral.com/Forums/Topic1043461-2671-1.aspx</link><description>[quote][b]toddasd (1/6/2011)[/b][hr]Is it considered cheating that I went to the BOL before answering the question and read "If two or more rows tie for a rank, each tied rows receives the same rank."?[/quote]I don't consider doing research and learning from it cheating.I'm not going to memorize every feature, trace flag, syntax, dmv of SQL Server. If I need something, I'll look it up :-)</description><pubDate>Thu, 06 Jan 2011 13:54:58 GMT</pubDate><dc:creator>Koen Verbeeck</dc:creator></item><item><title>RE: RANK() returns consecutive integers</title><link>http://www.sqlservercentral.com/Forums/Topic1043461-2671-1.aspx</link><description>Is it considered cheating that I went to the BOL before answering the question and read "If two or more rows tie for a rank, each tied rows receives the same rank."?</description><pubDate>Thu, 06 Jan 2011 12:37:24 GMT</pubDate><dc:creator>toddasd</dc:creator></item><item><title>RE: RANK() returns consecutive integers</title><link>http://www.sqlservercentral.com/Forums/Topic1043461-2671-1.aspx</link><description>Thanks for the question.</description><pubDate>Thu, 06 Jan 2011 11:33:34 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: RANK() returns consecutive integers</title><link>http://www.sqlservercentral.com/Forums/Topic1043461-2671-1.aspx</link><description>Thanks for the question!</description><pubDate>Thu, 06 Jan 2011 10:49:48 GMT</pubDate><dc:creator>UMG Developer</dc:creator></item><item><title>RE: RANK() returns consecutive integers</title><link>http://www.sqlservercentral.com/Forums/Topic1043461-2671-1.aspx</link><description>[quote][b]cengland0 (1/6/2011)[/b][hr]There are several ranking functions:. . .  One row is still a non empty rowset but that was not explained in the provided explanation.[/quote]You are absolutely right. Thank you for pointing out this boundary case.In my defense, I am still doing better than SQLS BOL which are not mentioning an empty set.;-)</description><pubDate>Thu, 06 Jan 2011 09:16:29 GMT</pubDate><dc:creator>Revenant</dc:creator></item><item><title>RE: RANK() returns consecutive integers</title><link>http://www.sqlservercentral.com/Forums/Topic1043461-2671-1.aspx</link><description>[quote][b]cengland0 (1/6/2011)[/b][hr]Another way to put this is if the question said:In a non-empty rowset, ROW_NUMBER() always returns consecutive integers.What would you answer?  True or False?I'd still answer False because it's possible to have a one-row rowset but the author is probably thinking True.[/quote]I guess I'd first check to see if you are the author of that question ;)But had I seen such a question before today, then I think there's about 80% chance I'd have replied True.If the correct answer had been False because of PARTITION BY, I would have slapped myself on the forehead and complimented the question's author.If the correct answer had been False because of a single-row rowset "not being consecutive", I would have felt misled and cheated.</description><pubDate>Thu, 06 Jan 2011 07:32:51 GMT</pubDate><dc:creator>Hugo Kornelis</dc:creator></item><item><title>RE: RANK() returns consecutive integers</title><link>http://www.sqlservercentral.com/Forums/Topic1043461-2671-1.aspx</link><description>Another way to put this is if the question said:In a non-empty rowset, ROW_NUMBER() always returns consecutive integers.What would you answer?  True or False?I'd still answer False because it's possible to have a one-row rowset but the author is probably thinking True.  I did get the answer for this QOTD correct.</description><pubDate>Thu, 06 Jan 2011 05:16:28 GMT</pubDate><dc:creator>cengland0</dc:creator></item><item><title>RE: RANK() returns consecutive integers</title><link>http://www.sqlservercentral.com/Forums/Topic1043461-2671-1.aspx</link><description>[quote][b]WayneS (1/6/2011)[/b][hr]Yes, there are several. However, this question is about the RANK() function, so why even bring these others into the mix?[/quote]Because I usually have to look them up to make sure I'm using the right one.  But in this case, I didn't have to look anything up because none of them would return consecutive integers (when there is a one-row result).[quote]Are you just trying to find fault with the question?[/quote]Not necessarily.  I do work for a very large company, in the training organization, and would consider myself an expert on quizzes.  There have been cases of companies firing employees during training for failing tests.  To avoid legal issues, you better look at each question carefully to make sure the answer they selected can never be a correct answer.  For this reason, I am always looking at these QOTD's with a different eye than a regular person.In a previous company, I have been involved in the process of firing and disciplinary actions of employees not passing tests.  I've also had to gather supporting documentation to take to court when an ex-employee took legal action.</description><pubDate>Thu, 06 Jan 2011 05:07:17 GMT</pubDate><dc:creator>cengland0</dc:creator></item><item><title>RE: RANK() returns consecutive integers</title><link>http://www.sqlservercentral.com/Forums/Topic1043461-2671-1.aspx</link><description>[quote][b]cengland0 (1/6/2011)[/b][hr]There are several ranking functions:RANKDENSE_RANKNTILEROW_NUMBER[/quote] Yes, there are several. However, this question is about the RANK() function, so why even bring these others into the mix?[quote]When the question asked will it always return consecutive integers, I knew right away that it was false because none of them will always return consecutive integers if there is only one row.  One row is still a non empty rowset but that was not explained in the provided explanation.[/quote]Are you just trying to find fault with the question?A better argument would have been that all of the windowing functions accept a PARTITION BY clause, which re-starts the numbering - thus the results are not always sequential. However, sometimes you just have to go with what you know the author meant to convey.</description><pubDate>Thu, 06 Jan 2011 04:50:35 GMT</pubDate><dc:creator>WayneS</dc:creator></item><item><title>RE: RANK() returns consecutive integers</title><link>http://www.sqlservercentral.com/Forums/Topic1043461-2671-1.aspx</link><description>[quote][b]cengland0 (1/6/2011)[/b][hr][quote][b]Hugo Kornelis (1/6/2011)[/b][hr][quote][b]cengland0 (1/6/2011)[/b][hr]Meh, I could just as well say that everything is consecutive in a single-row rowset.According to [url=http://www.thefreedictionary.com/consecutive]http://www.thefreedictionary.com/consecutive[/url], "consecutive" means (a.o.) "Following one after another without interruption" - and in a single row row-set, there can never be any interruption.[/quote]You forgot a major component of the definition of consecutive.  The "one after another" part.  When you have a one row rowset, how can you have one after another in the resultset?  That means you must have a minimum of two rows to have one after another.[/quote]If you really want to take it to a filosophical level, you could argue that one row comes after nothing.</description><pubDate>Thu, 06 Jan 2011 02:42:38 GMT</pubDate><dc:creator>Koen Verbeeck</dc:creator></item><item><title>RE: RANK() returns consecutive integers</title><link>http://www.sqlservercentral.com/Forums/Topic1043461-2671-1.aspx</link><description>[quote][b]Hugo Kornelis (1/6/2011)[/b][hr][quote][b]cengland0 (1/6/2011)[/b][hr]Meh, I could just as well say that everything is consecutive in a single-row rowset.According to [url=http://www.thefreedictionary.com/consecutive]http://www.thefreedictionary.com/consecutive[/url], "consecutive" means (a.o.) "Following one after another without interruption" - and in a single row row-set, there can never be any interruption.[/quote]You forgot a major component of the definition of consecutive.  The "one after another" part.  When you have a one row rowset, how can you have one after another in the resultset?  That means you must have a minimum of two rows to have one after another.</description><pubDate>Thu, 06 Jan 2011 02:38:10 GMT</pubDate><dc:creator>cengland0</dc:creator></item><item><title>RE: RANK() returns consecutive integers</title><link>http://www.sqlservercentral.com/Forums/Topic1043461-2671-1.aspx</link><description>[quote][b]cengland0 (1/6/2011)[/b][hr]When the question asked will it always return consecutive integers, I knew right away that it was false because none of them will always return consecutive integers if there is only one row.[/quote]Meh, I could just as well say that everything is consecutive in a single-row rowset.According to [url=http://www.thefreedictionary.com/consecutive]http://www.thefreedictionary.com/consecutive[/url], "consecutive" means (a.o.) "Following one after another without interruption" - and in a single row row-set, there can never be any interruption.The reason that RANK does not return consecutive values is how ties are handled - for instance, if the RANK is based on the scores {9.6, 8.4, 9.6}, the results would be[code="other"]Score Rank9.6   19.6   18.4   3[/code]Because two rows get the rank 1, the value 2 is skipped. That makes the values non-consecutive.</description><pubDate>Thu, 06 Jan 2011 02:32:39 GMT</pubDate><dc:creator>Hugo Kornelis</dc:creator></item><item><title>RE: RANK() returns consecutive integers</title><link>http://www.sqlservercentral.com/Forums/Topic1043461-2671-1.aspx</link><description>Nice and easy. Thanks!</description><pubDate>Thu, 06 Jan 2011 02:12:58 GMT</pubDate><dc:creator>Koen Verbeeck</dc:creator></item><item><title>RE: RANK() returns consecutive integers</title><link>http://www.sqlservercentral.com/Forums/Topic1043461-2671-1.aspx</link><description>There are several ranking functions:RANKDENSE_RANKNTILEROW_NUMBERWhen the question asked will it always return consecutive integers, I knew right away that it was false because none of them will always return consecutive integers if there is only one row.  One row is still a non empty rowset but that was not explained in the provided explanation.</description><pubDate>Thu, 06 Jan 2011 02:09:06 GMT</pubDate><dc:creator>cengland0</dc:creator></item><item><title>RANK() returns consecutive integers</title><link>http://www.sqlservercentral.com/Forums/Topic1043461-2671-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/questions/T-SQL/71919/"&gt;RANK() returns consecutive integers&lt;/A&gt;[/B]</description><pubDate>Wed, 05 Jan 2011 21:02:51 GMT</pubDate><dc:creator>Revenant</dc:creator></item></channel></rss>