Tuesday, January 19, 2010

SQL functions - UNION, EXCEPT, INTERSECT

The three functions in SQL 2005 cam combine the data from two or more tables and display them in one dataset.

Union (all) - union two or more table data together, by default it will only show the DISTINCT row data unless the "all" option is used

EXCEPT - pick the data from first table but the data not exist in the second table

INTERSECT - Pick the data rows only exist in the first table and the second table.

EXCEPT and INTERSECT function can be implemented by using the join function in SQL queries. but these two features are sometime more simplified and the code is easier to read.

No comments:

Post a Comment