04 | Using Set Operators Graeme Malcolm | Senior Content Developer, Microsoft Geoff Allix | Principal Technologist, Content Master.

Slides:



Advertisements
Similar presentations
Using the Set Operators
Advertisements

Advanced SQL (part 1) CS263 Lecture 7.
Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 8 Advanced SQL.
9 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Using the Set Operators Assist. Prof. Pongpisit Wuttidittachotti, Ph.D. Faculty.
WRITING BASIC SQL SELECT STATEMENTS Lecture 7 1. Outlines  SQL SELECT statement  Capabilities of SELECT statements  Basic SELECT statement  Selecting.
02 | Advanced SELECT Statements Brian Alderman | MCT, CEO / Founder of MicroTechPoint Tobias Ternstrom | Microsoft SQL Server Program Manager.
Objectives After completing this lesson, you should be able to do the following: Define subqueries Describe the types of problems that the subqueries.
Chapter 2 Basic SQL SELECT Statements
SQL. Basic Structure SQL is based on set and relational operations with certain modifications and enhancements A typical SQL query has the form: select.
Chapter 2 Basic SQL SELECT Statements Oracle 10g: SQL.
Chapter 9 Joining Data from Multiple Tables
Graeme Malcolm | Senior Content Developer, Microsoft Geoff Allix | Principal Technologist, Content Master.
04 | Grouping and Aggregating Data Brian Alderman | MCT, CEO / Founder of MicroTechPoint Tobias Ternstrom | Microsoft SQL Server Program Manager.
Relational Algebra A presentation for CS 457 By Dawn Haddan.
M Taimoor Khan Course Objectives 1) Basic Concepts 2) Tools 3) Database architecture and design 4) Flow of data (DFDs)
SELECT Statements Lecture Notes Sree Nilakanta Fall 2010 (rev)
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
10 | Programming with Transact-SQL Graeme Malcolm | Senior Content Developer, Microsoft Geoff Allix | Principal Technologist, Content Master.
Set Operations Objectives of the Lecture : To consider the Set Operations Union, Difference and Intersect; To consider how to use the Set Operations in.
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS Dr. Adam Anthony Fall 2012.
Advanced Relational Algebra & SQL (Part1 )
15 Copyright © Oracle Corporation, All rights reserved. Using SET Operators.
Creating and Managing Content Types Module 9. Overview  Understanding Content Types  Creating and Using Site Columns  Creating and Using Site Content.
SQL Select Statement IST359.
Copyright © 2004, Oracle. All rights reserved. Using the Set Operators.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
Web Programming MySql JDBC Web Programming.
Using SET Operators Fresher Learning Program January, 2012.
1 SQL – IV Grouping data from tables in SQL –The concept of grouping –GROUP BY clause –HAVING Clause –Determining whether values are unique –Group by using.
05 | SET Operators, Windows Functions, and Grouping Brian Alderman | MCT, CEO / Founder of MicroTechPoint Tobias Ternstrom | Microsoft SQL Server Program.
Manipulating Data Lesson 3. Objectives Queries The SELECT query to retrieve or extract data from one table, how to retrieve or extract data by using.
Writing Basic SQL SELECT Statements Lecture
 CONACT UC:  Magnific training   
Select Complex Queries Database Management Fundamentals LESSON 3.1b.
IFS180 Intro. to Data Management Chapter 10 - Unions.
Querying with Transact-SQL
02 | Advanced SELECT Statements
11 | Error Handling and Transactions
10 | Programming with Transact-SQL
Database Systems: Design, Implementation, and Management Tenth Edition
09 | Modifying Data Graeme Malcolm | Senior Content Developer, Microsoft Geoff Allix | Principal Technologist, Content Master.
Using the Set Operators
05 | Using Functions and Aggregating Data
20761A 11: Using Set Operators Module 11   Using Set Operators.
03 | Querying Multiple Tables with Joins
08 | Grouping Sets and Pivoting Data
Sorting and Filtering Data
Querying Multiple Tables
Writing Basic SQL SELECT Statements
06 | Using Subqueries and APPLY
20761B 12: Using Set Operators Module 12   Using Set Operators.
20761B 12: Using Set Operators Module 12   Using Set Operators.
Using the Set Operators
09 | Modifying Data Graeme Malcolm | Senior Content Developer, Microsoft Geoff Allix | Principal Technologist, Content Master.
Writing SELECT Queries
02 | Querying Tables with SELECT
07 | Using Table Expressions
The Relational Algebra
Access: SQL Participation Project
SQL Fundamentals in Three Hours
Writing Basic SQL SELECT Statements
Contents Preface I Introduction Lesson Objectives I-2
Chapter 8 Advanced SQL.
SQL set operators and modifiers.
Geo-Databases: lecture 4 Complex Queries in SQL
Using the Set Operators
Manipulating Data Lesson 3.
02 | Querying Tables with SELECT
Group Operations Part IV.
Presentation transcript:

04 | Using Set Operators Graeme Malcolm | Senior Content Developer, Microsoft Geoff Allix | Principal Technologist, Content Master

Module Overview What are UNION Queries? What are INTERSECT Queries? What are EXCEPT Queries?

What are UNION Queries? UNION returns a result set of distinct rows combined from all statements UNION removes duplicates during query processing (affects performance) UNION ALL retains duplicates during query processing -- only distinct rows from both queries are returned SELECT countryregion, city FROM HR.Employees UNION SELECT countryregion, city FROM Sales.Customers;

UNION Guidelines Column aliases Number of columns Data types Must be expressed in first query Number of columns Must be the same Data types Must be compatible for implicit conversion (or converted explicitly)

Creating UNION Queries

What are INTERSECT Queries? INTERSECT returns only distinct rows that appear in both result sets -- only rows that exist in both queries will be returned SELECT countryregion, city FROM HR.Employees INTERSECT SELECT countryregion, city FROM Sales.Customers;

What are EXCEPT Queries? EXCEPT returns only distinct rows that appear in the first set but not the second Order in which sets are specified matters -- only rows from Employees will be returned SELECT countryregion, city FROM HR.Employees EXCEPT SELECT countryregion, city FROM Sales.Customers;

Demo: Creating INTERSECT and EXCEPT Queries

Using Set Operators What are UNION Queries? What are INTERSECT Queries? What are EXCEPT Queries? Lab: Using Set Operators