Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 select query

Author  Topic 

esambath
Yak Posting Veteran

89 Posts

Posted - 2009-10-22 : 08:01:54
Hi experts,

i have one table LP_Articles

CREATE TABLE [LP_Articles] (
[ArticleId] [bigint] NULL ,
[Noofimpression] [bigint] NULL ,
[Topic] [varchar] (50) NULL

)

insert into LP_Articles(ArticleId,Noofimpression,Topic)values(1,0,'A')
insert into LP_Articles(ArticleId,Noofimpression,Topic)values(2,0,'B')
insert into LP_Articles(ArticleId,Noofimpression,Topic)values(3,0,'C')
insert into LP_Articles(ArticleId,Noofimpression,Topic)values(4,0,'D')
insert into LP_Articles(ArticleId,Noofimpression,Topic)values(5,1,'E')
insert into LP_Articles(ArticleId,Noofimpression,Topic)values(6,1,'F')
insert into LP_Articles(ArticleId,Noofimpression,Topic)values(7,1,'G')
insert into LP_Articles(ArticleId,Noofimpression,Topic)values(8,2,'H')
insert into LP_Articles(ArticleId,Noofimpression,Topic)values(9,3,'I')
insert into LP_Articles(ArticleId,Noofimpression,Topic)values(10,4,'J')
insert into LP_Articles(ArticleId,Noofimpression,Topic)values(11,12,'K')

select * from LP_Articles order by Noofimpression desc

we need to display the top 5 articles seperately

Output

------------------------------------------
ArticleId,Noofimpression,Topic, Reference
------------------------------------------
11 12 K 1
10 4 J 1
9 3 I 1
8 2 H 1
7 1 G 1
5 1 E 0
6 1 F 0
1 0 A 0
2 0 B 0
3 0 C 0
4 0 D 0


if you need more clarification i will explain

thanks an advance
sambath

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-10-22 : 09:11:46
So how looks your WANTED output?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

NeilG
Aged Yak Warrior

530 Posts

Posted - 2009-10-22 : 11:18:01
Do you mean you want the top 5 a full list

select top 5 * from LP_Articles order by Noofimpression desc

select * from LP_Articles order by Noofimpression desc
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-10-22 : 13:08:03
are you using sql 2005?
Go to Top of Page
   

- Advertisement -