|
Posted by Gints Plivna on 01/24/08 10:25
On 24 Janv., 01:17, Erland Sommarskog <esq...@sommarskog.se> wrote:
> Gints Plivna (gints.pli...@gmail.com) writes:
> > I'm quite sure row_number won't help me in this case, because I'd like
> > to limit found number of rows. row_number actually must have order by
> > clause and ordering before limiting returned number of rows is the
> > thing I'd like to avoid.
>
> That can be achieved with row_number with some trickery. Consider:
>
> with numbered AS (
> select *, rn = row_number() OVER (order by x)
> from (SELECT *, x = 'x' FROM Orders) as s
> )
> SELECT * FROM numbered WHERE rn < 20
> ORDER BY CustomerID
Ahh that's real trickery! :)
OK I'll remember it just in case in the future I'll need something
like that!
Thanks!
Gints
Navigation:
[Reply to this message]
|