I have a query similar to this:SELECT Col1, ROW_NUMBER() OVER (ORDER BY Col1)FROM SomeTblUNION ALLSELECT Col1, ROW_NUMBER() OVER (ORDER BY Col1)FROM SomeTblWHERE Col2 > 100
I want to inject ROW_NUMBER() but ROW_NUMBER() restarts at 1 on the second SELECT statement.I could make it a subquery by wrapping it inside the FROM clause like this:SELECT Col1, ROW_NUMBER() OVER (ORDER BY Col1)FROM(SELECT Col1FROM SomeTblUNION ALLSELECT Col1FROM SomeTblWHERE Col2 > 100)subquery
But I was wondering if there's an alternative solution without using derived tables. Is it possible to reference the first SELECT statement and, somehow, continue counting where it left off?Thank you very much for any help, in advance.