| Author |
Topic |
|
pelegk2
Aged Yak Warrior
723 Posts |
Posted - 2007-09-08 : 15:53:25
|
| i have a table:id,categoryref,datatype,innerOrder1,3,1,112,3,1,193,3,1,24,2,1,85,2,1,66,3,1,37,3,1,1........and i want to get first 3 resukts where datatype=1and categoryref=3 and order by innerORder (where innerORder is the order for each categoryref)how do i do this?thnaks in advancepelegIsrael -the best place to live in aftr heaven 9but no one wan't to go there so fast -:) |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2007-09-08 : 16:17:47
|
| how long have you been here pelegk2?anyways...select top 3 *from resultswhere datatype=1 and categoryref=3order by innerorder asc--------------------keeping it simple... |
 |
|
|
pelegk2
Aged Yak Warrior
723 Posts |
Posted - 2007-09-08 : 16:23:32
|
| sorry mu mistake wihtought the categoryref=3i need all the groups:)Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:) |
 |
|
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2007-09-08 : 20:13:54
|
| [code]create table #Test(id int ,categoryref int,datatype int,innerOrder int)insert into #Test(ID,categoryref,datatype,innerorder)select 1,3,1,11union allselect 2,3,1,19union allselect 3,3,1,2union allselect 4,2,1,8union allselect 5,2,1,6union allselect 6,3,1,3union allselect 7,3,1,1Select *from ( select row_Number() over (partition by categoryref order by innerorder) as rowID ,* from #Test ) awhere a.RowID <=3[/code] |
 |
|
|
|
|
|