﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2012 / SQL Server 2012 -  T-SQL  / simple MAX question / 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>Sat, 25 May 2013 23:00:23 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: simple MAX question</title><link>http://www.sqlservercentral.com/Forums/Topic1406759-3077-1.aspx</link><description>[quote][b]Pete-600513 (1/19/2013)[/b][hr]Thank you very much. I thought there might be an easy way with the max function[/quote]You were right.[code="sql"]SELECT DT.max_score, A.name, a.dobFROM dbo.Exam A	INNER JOIN (SELECT MAX(score) max_score			FROM dbo.Exam			) DT ON DT.max_score = A.score [/code]</description><pubDate>Wed, 13 Feb 2013 17:07:32 GMT</pubDate><dc:creator>Sergiy</dc:creator></item><item><title>RE: simple MAX question</title><link>http://www.sqlservercentral.com/Forums/Topic1406759-3077-1.aspx</link><description>Thank you very much. I thought there might be an easy way with the max function, but it looks like I need to use a different function...so will go and do some research.ThanksPete</description><pubDate>Sat, 19 Jan 2013 10:15:30 GMT</pubDate><dc:creator>Pete-600513</dc:creator></item><item><title>RE: simple MAX question</title><link>http://www.sqlservercentral.com/Forums/Topic1406759-3077-1.aspx</link><description>Sounds like a homework question .. in case it is NOT ... please post the table definition(s), sample data and required results.You can do this quickly and very easily..... click on the first link in my signature block and read the article.  Now the article contains all the necessary code for table definition, creating sample data and last but not least the required results.</description><pubDate>Mon, 14 Jan 2013 08:34:52 GMT</pubDate><dc:creator>bitbucket-25253</dc:creator></item><item><title>RE: simple MAX question</title><link>http://www.sqlservercentral.com/Forums/Topic1406759-3077-1.aspx</link><description>For an in-depth look at ranking functions check out BOL. [url=http://msdn.microsoft.com/en-us/library/ms173454.aspx]http://msdn.microsoft.com/en-us/library/ms173454.aspx[/url]</description><pubDate>Mon, 14 Jan 2013 08:34:23 GMT</pubDate><dc:creator>Sean Lange</dc:creator></item><item><title>RE: simple MAX question</title><link>http://www.sqlservercentral.com/Forums/Topic1406759-3077-1.aspx</link><description>That would be one for a ranking function.  Depending on how you want to do what you need to do and then also what you want to do if the 2 people have the max score.ROW_NUMBER()RANK()DENSE_RANK()NTILE()Each behaves differently.[code="sql"]DECLARE @Table TABLE (Name CHAR(3), DOB DATE, Score INT)INSERT INTO @Table VALUES ('Ant',GETDATE(),10),('Bob',GETDATE()-1,10),('Mum', GETDATE()-2,5)SELECT * FROM @Table;with RowNumber as(SELECT ROW_NUMBER() OVER(ORDER BY Score DESC) AS RowNum, Name, DOB, Score FROM @Table)select * from RowNumber where RowNum = 1;with ranking as(SELECT RANK() OVER(ORDER BY Score DESC) AS RowNum,Name, DOB, Score FROM @Table)SELECT * from ranking where RowNum = 1;with dense_ranking as(SELECT DENSE_RANK() OVER(ORDER BY Score DESC) AS RowNum,Name,DOB,Score FROM @Table)SELECT * FROM dense_ranking WHERE RowNum = 1;with ntileing as(SELECT NTILE(2) OVER(ORDER BY Score DESC) AS RowNum, Name, DOB, Score FROM @Table)SELECT * FROM ntileing WHERE RowNum = 1[/code]</description><pubDate>Mon, 14 Jan 2013 08:32:42 GMT</pubDate><dc:creator>anthony.green</dc:creator></item><item><title>simple MAX question</title><link>http://www.sqlservercentral.com/Forums/Topic1406759-3077-1.aspx</link><description>Hi there, I would like to find the MAX (score for example) and return who got that score. Imagine if I have a table of 3 fields: score, name and dob. How Do I return who has got the max score and their dob?thanksPete</description><pubDate>Mon, 14 Jan 2013 08:21:55 GMT</pubDate><dc:creator>Pete-600513</dc:creator></item></channel></rss>