Author |
Topic |
sagavb
Starting Member
18 Posts |
Posted - 2009-06-01 : 00:31:54
|
Hi there,Is it possible to get top 2 record from below tableTable name: testname salMr.X 800Mr.Y 1000Mr.Z 1500Mr.A 2000Expected output should be asname salMr.Y 1000Thanks in advanceSaga |
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-06-01 : 01:07:18
|
Saga sir,do u have any identity column or primary key?Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceled |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-06-01 : 01:15:26
|
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/09/12/return-top-n-rows.aspx KH[spoiler]Time is always against us[/spoiler] |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-06-01 : 01:23:22
|
Try this!select top 1 from (select top 2 * from test order by sal) t order by sal descSenthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceled |
|
|
sagavb
Starting Member
18 Posts |
Posted - 2009-06-01 : 01:36:48
|
Senthil Sir,I dont think it will work.Can you copy that query and run it?RegardsSagaquote: Originally posted by senthil_nagore Try this!select top 1 from (select top 2 * from test order by sal) t order by sal descSenthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceled
|
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-06-01 : 01:37:55
|
quote: Originally posted by senthil_nagore Try this!select top 1 * from (select top 2 * from test order by sal) t order by sal descSenthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceled
KH[spoiler]Time is always against us[/spoiler] |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-06-01 : 01:40:22
|
saga sir,just i miss the "*" as khtan pointed out... u must debug it saga...else ask ur boss...Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceled |
|
|
sagavb
Starting Member
18 Posts |
Posted - 2009-06-01 : 01:53:13
|
Hey Thanks laquote: Originally posted by senthil_nagore saga sir,just i miss the "*" as khtan pointed out... u must debug it saga...else ask ur boss...Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceled
|
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-06-01 : 02:38:00
|
quote: Originally posted by sagavb Hi there,Is it possible to get top 2 record from below tableTable name: testname salMr.X 800Mr.Y 1000Mr.Z 1500Mr.A 2000Expected output should be asname salMr.Y 1000Thanks in advanceSaga
Your expected output contradicts your topic "Selecting Top 2 record"What basis do you want to get it?MadhivananFailing to plan is Planning to fail |
|
|
sagavb
Starting Member
18 Posts |
Posted - 2009-06-01 : 02:45:21
|
Hi Madhivanan,I meant, selecting 2nd record from a tableRegardsSagaquote: Originally posted by madhivanan
quote: Originally posted by sagavb Hi there,Is it possible to get top 2 record from below tableTable name: testname salMr.X 800Mr.Y 1000Mr.Z 1500Mr.A 2000Expected output should be asname salMr.Y 1000Thanks in advanceSaga
Your expected output contradicts your topic "Selecting Top 2 record"What basis do you want to get it?MadhivananFailing to plan is Planning to fail
|
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-06-01 : 04:30:18
|
What basis do you need second record?MadhivananFailing to plan is Planning to fail |
|
|
|