i have 5 tables (tab1, tab2, tab3, tab4 and tab5) and all the 5 tables has same table definition. I want to select 1st row of each table and insert those 5 rows in new table(newtab). I was only able to write query that select 1 row from one table and insert that into newtab. How can i select 1st 5 rows from all the table and insert them into newtab in one query.
In this case i have to deal with only 5 tables so its easy using union but when i want to select 1st rows from 100 tables then the query will become but lengthy using UNION.
IDENTITY
column? A specificORDER BY
clause? Or will any particular row be sufficient (as inTOP(1)
)?