I have an sql query that returns rows from two tables with same column names. I need a row number of all records in a complete result set.
Following is the query
<
A slightly better way would be :-
with resultset1 as(
select Id, VersionNumber from documents where id=5
Union all
select Id, VersionNumber from versions where id=5
), resultset2 as(
select Id, VersionNumber, ROW_NUMBER() OVER(ORDER BY Id) ROW_NUM
from resultset1
)
select * from resultset2 WHERE VersionNumber = 5