Presentation is loading. Please wait.

Presentation is loading. Please wait.

IFS180 Intro. to Data Management Chapter 10 - Unions.

Similar presentations


Presentation on theme: "IFS180 Intro. to Data Management Chapter 10 - Unions."— Presentation transcript:

1 IFS180 Intro. to Data Management Chapter 10 - Unions

2 SQL Unions Dealing with two or more result sets and combining into single result set Unlike both inner and outer joins, where we work with individual columns. Union interleaves the rows from the result sets into one set

3 Union SQL Basic Syntax: Select statement UNION (ALL) Select statement ALL is optional and will include duplicate rows from the result sets. Note, the default is not to include duplicates Union Conditions: Same number of columns in select statement Columns must be comparable data types

4 SQL Unions Select statements can be as simple or complex as needed to solve the problem and can be in any combination of complexity Good practice mandates to build each individual query first then build the union query If where statements are used, they can be used on any or all of the select statements combined to make the union query

5 SQL Unions Sorting (Order by) No need to sort within any of the individual select statements (waste of time and resources) Order By statement should be placed at the end of the Union (i.e. after the last select statement)

6 SQL Union Uses: Produce reports from tables with “common” values Other options for SQL Unions Many times, using complex where clauses can replace SQL Unions Many times, database designers are replacing multiple tables suitable for SQL Unions with one table


Download ppt "IFS180 Intro. to Data Management Chapter 10 - Unions."

Similar presentations


Ads by Google