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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Top n records

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-04-05 : 08:06:05
Raghu writes "Hi,
I have a table "tblFiles" with two fields "FileID" and "FileName". There are 100 Records. 5 sets of 20 records have the same fileid. For example FileID = 1 will have 20 different filenames. FileID 2 will have 20 different filenames. I want a result of 3 records per file id. How will I get it?

Thanks for help."

Jay99

468 Posts

Posted - 2002-04-05 : 09:21:58
maybe something


create table <temptablename>
<tabledef>

insert <tempateblename>
select top 3
from tblFiles
where FileID = 1

insert <tempateblename>
select top 3
from tblFiles
where FileID = 2

insert <tempateblename>
select top 3
from tblFiles
where FileID = 3

 

Jay
<O>
Go to Top of Page

chadmat
The Chadinator

1974 Posts

Posted - 2002-04-05 : 21:59:26
Or if you just want to qury without the temp table:


select top 3
from tblFiles
where FileID = 1

UNION

select top 3
from tblFiles
where FileID = 2

UNION

select top 3
from tblFiles
where FileID = 3



-Chad

Go to Top of Page
   

- Advertisement -