Select only n number of records from a specific field [Resolved]

Posted by Modit under Sql Server on 7/17/2012 | Points: 10 | Views : 958 | Status : [Member] | Replies : 2
I have a table called "Details" in that i have records , like

uid name level
1 a 1
2 b 1
3 c 1
4 d 1
5 e 2
6 f 2
7 g 2
8 h 3
9 i 3
10 j 3

I want to get only 2 records that have level 1 , and all the rest of the records. like

uid name level
1 a 1
2 b 1
5 e 2
6 f 2
7 g 2
8 h 3
9 i 3
10 j 3


I dont want the TOP 8 records, only 2 records from specific level, and rest all of the records from other levels should be retrieved as well.




Responses

Posted by: Raees on: 7/18/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
select a.* from(select top 2 * from Details order by uid asc)a
union
select r.* from(select * from Details where level <>1)r

RK

Modit, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dotnetrajanikanth on: 7/17/2012 [Member] Starter | Points: 25

Up
0
Down
If you dont want top you can try UNION

____________
www.flickr.com/photos/psdesigner/

Modit, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response