Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: Wanted Top 3 rows...


Message #1 by kedararunpande@c... on Wed, 31 May 2000 11:6:5
Hi Everybody,

I am having some problems with getting top 3 rows from the resultset.

My Query is

	Select	NM.NewsNo,
		NM.NewsTitle,
		NM.NewsTypeID
	from 	NewsMaster NM
	where	NM.NewsNo in ( Select  ND.NewsNo
			       from    NewsDetails ND
			       where   ND.commitflag = 1 and
				       NewsSRNo in ( Select  max ( NF.NewsSRNo )
						     from    NewsFileInfo NF
						     where   NF.CommitFlag = 1 
							     Group by NF.NewsTypeID,
								      CommitFlag )) and
		Substring ( NM.NewsVisibilityFlag,1,1) = 1
		order by NM.NewsTypeID,
			 NewsNo desc


NewsNo  NewsTitle                     NewsTypeID  
------- ----------------------------- ----------- 
12      hummara zamaana hai           1
11      abcdefgh                      1
10      abcd                          1
30      humm hai rahi pyaar ke        2
17      hum aapke hai truck waaley    2
16      jo jeeta wohi sikander        2
15      yeh waqt hamaaraa hai         2
6       Welcome to the news           2
23      Khiladi number 1              3
22      Zindagi ek juaa               3
21      Haryaali aur raasta           3
20      bahaar aaaney tak             3
19      zindagi ka safar              3
29      koi ba nahi mila!!!           4
28      junglee truck driver          4
27      khabri peeley  ki jai         4
26      khabri laal ki jai            4
25      Kal parso                     4
3       Good Performance in 99-00     4
1       Careers in trans industry     4

(20 row(s) affected)


I want only top 3 news numbers for each NewsTyeID (e.g. 29,28,27 for 
newstypeid 4 ) from this set of records.

I tried "TOP" , group by with TOP but it's not working .

If any body is there with solution, It will be a great help.

Regards

Kedar


  Return to Index