Developing Portable Applications : 3. Application Considerations : Implementation Differences : UNION of Select First N
 
Share this page                  
UNION of Select First N
With Microsoft SQL Server, when a first N clause modifies a select union statement, the first N clause only applies to the first select in the query. This behavior differs from the Ingres behavior. With Ingres, the first N clause applies to the entire query, not just the first select.
Consider a two table example. Each table has only one column. Table1.column1 has values 1 and 2. Table2.column2 has values 3, 4 and 5. Select first 2 * from table1 union select * from table2, yields 1 and 2, with Ingres. With MS SQL Server it yields 1, 2, 3, 4 and 5, because the first N restriction only applies to the first select of the query.