SQL Server LIMIT top QUERY -


how can limit top query record.

example:

the result should until value of col2 b.

 id     col1        col2   7       1             6       2             5       1             4       3           b   3       1             2       4             1       1           b 

you can use row_number() windowing function:

;with x (     select col1, col2, row_number() over(order id desc) rn     table1 ) select col1, col2 x x1 not exists (     select 1     x x2     x2.rn <= x1.rn     , x2.col2 = 'b' ) 

sql fiddle


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -