T-SQL select sample records of distinct values

In SQL server 2008 I have table Theory with columns Thesis and Class.

Thesis                   Class
<this is sample text>    1
<this is sample text>    2
<this is sample text>    2
<this is sample text>    3
<this is sample text>    3
<this is sample text>    1
<this is sample text>    3
<this is sample text>    1
<this is sample text>    1
<this is sample text>    2

I want to write select statement that will return two records of each class.

Many thanks

Answers


;WITH T AS
(
SELECT Thesis, 
       Class, 
       ROW_NUMBER() OVER (PARTITION BY Class ORDER BY (SELECT 0) ) rn
FROM Theory 
)
SELECT Thesis, Class
FROM T 
WHERE rn <=2

Need Your Help

How to set jslider default pointers programmatically on page load

javascript jquery jquery-plugins jslider jquery-slider

I am using jQuery Slider plugin script here is my HTML &amp; JQuery code.

php, curl, headers and content-type

php curl http-headers

I am having some trouble working with curl and headers returned by servers.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.