Groups | Blog | Home
all groups > sql server clients > june 2004 >

sql server clients : Simple Query


Noor
6/25/2004 9:25:31 AM
Here is the data

ID Date Name
1 '01-01-2001' Noor
2 '01-04-2001' ali
3 '01-03-2001' Farhan
4 '01-05-2001' iqbal
5 '01-06-2001' Urooj


I want the top 3 descending order records data wise like I want the data
like this

ID Date Name
2 '01-04-2001' ali
4 '01-05-2001' iqbal
5 '01-06-2001' Urooj


Can any body give me the query.. I don't wanna use Temperary table. I only
want to use query.

thanks
Noor



Anith Sen
6/25/2004 10:08:44 AM
Do:

SELECT *
FROM tbl t1
WHERE t1.flag = 0
OR ( SELECT COUNT( * )
FROM tbl t2
WHERE t2.dt > t1.dt
AND t2.flag = 1 ) < 3 ;

--
Anith

Noor
6/25/2004 10:21:27 AM
Please ignore my previous query plz read the following one..

Here is the data

ID Date Name flag
1 '01-01-2001' Noor 1
2 '01-04-2001' ali 1
3 '01-03-2001' Farhan 1
4 '01-05-2001' iqbal 1
5 '01-06-2001' Urooj 1
6 '01-01-2001' Noorali 0
7 '01-04-2001' ali 0
8 '01-03-2001' Farhaniqbla 0
9 '01-05-2001' iqbalfarhan 0
10 '01-06-2001' Uroojkhan 0
11 '01-06-2001' Uroojkhan 0

I want the top 3 descending order records data wise which flag = 1 and get
all the data of flag = 0 like I want the data
like this

ID Date Name Flag
2 '01-04-2001' ali 1
4 '01-05-2001' iqbal 1
5 '01-06-2001' Urooj 1
6 '01-01-2001' Noorali 0
7 '01-04-2001' ali 0
8 '01-03-2001' Farhaniqbla 0
9 '01-05-2001' iqbalfarhan 0
10 '01-06-2001' Uroojkhan 0
11 '01-06-2001' Uroojkhan 0



Can any body give me the query.. I don't wanna use Temperary table. I only
want to use query.

thanks
Noor




[quoted text, click to view]

AddThis Social Bookmark Button