There is a data in the following table
Account No. Stat. No. Line. No.
1 4 5
1 2 3
1 6 4
2 5 6
2 3 7
2 4 8
3 9 1
3 8 2
3 5 4
1 0 84
2 5 7
3 6 6
1 56 9
1 41 8
2 41 8
Now I want the data of top 2 records of each Account No. like this
Account No. Stat. No. Line No.
1 4 5
1 2 3
2 5 6
2 3 7
3 9 1
3 8 2
Can any body let me know any query
Thanks
NOOR
On Tue, 25 May 2004 19:23:23 +0500, Noorali Issani wrote:
>There is a data in the following table
>Account No. Stat. No. Line. No.
> 1 4 5
> 1 2 3
> 1 6 4
> 2 5 6
> 2 3 7
> 2 4 8
> 3 9 1
> 3 8 2
> 3 5 4
> 1 0 84
> 2 5 7
> 3 6 6
> 1 56 9
> 1 41 8
> 2 41 8
>Now I want the data of top 2 records of each Account No. like this
>Account No. Stat. No. Line No.
> 1 4 5
> 1 2 3
> 2 5 6
> 2 3 7
> 3 9 1
> 3 8 2
>Can any body let me know any query
>Thanks
>NOOR
>
Hi Noor,
The short anwer to that woud be 'no'.
Tables in a relational database have no innate ordering. Asking for the
"top 2 rows" (or: first 2 rows) can only be done if you specify some sort
order by which to determine which 2 rows are "first".
If you can tell me *how* (what criteria) SQL Server should decide which 2
rows to return, than I can probably tell you how (which statements) to
write the query.
Best, Hugo
(Remove _NO_ and _SPAM_ to get my e-mail address)
|||A database stores information in the natural order, and this order depends
on the data files. However, when we try to retrieve this information, we
need to provide some business logic for the same.
What I understand from your posting, is that you want to retrieve only the
top 2 rows for each Account Number as they appear in the database. There is
no other business logic for that. Doing this will be very difficult as
there is no way to know what is in top 2. If you can design a business
logic behind the retrieval of this, I could better assist you.
Let me know about the logic and will talk later.
sanchans@.online.microsoft.com
This posting is provided "AS IS" with no warranties, and confers no rights.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment