The INTERSECT Operator

Slides:



Advertisements
Similar presentations
Using the Set Operators
Advertisements

Haas MFE SAS Workshop Lecture 3:
Introduction to SQL Session 2 Retrieving Data From Multiple Tables.
9 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Using the Set Operators Assist. Prof. Pongpisit Wuttidittachotti, Ph.D. Faculty.
Seminar #1 – Refreshing databases concepts and SQL CM036: Advanced Databases1 Seminar 1: Revisiting Databases and SQL Purpose To refresh basic concepts.
Objectives After completing this lesson, you should be able to do the following: Define subqueries Describe the types of problems that the subqueries.
11 Chapter 2: Basic Queries 2.1: Overview of the SQL Procedure 2.2: Specifying Columns 2.3: Specifying Rows.
SQL Chapter Two. Overview Basic Structure Verifying Statements Specifying Columns Specifying Rows.
4a. Structured Query Language - SELECT Statement Lingma Acheson Department of Computer and Information Science IUPUI CSCI N207 Data Analysis with Spreadsheets.
15 Copyright © Oracle Corporation, All rights reserved. Using SET Operators.
SQL Select Statement IST359.
Copyright © 2004, Oracle. All rights reserved. Using the Set Operators.
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
Using SET Operators Fresher Learning Program January, 2012.
Chapter 4: Combining Tables Vertically using PROC SQL 1 © Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
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.
11 Chapter 4: Subqueries 4.1: Noncorrelated Subqueries 4.2: Correlated Subqueries (Self-Study)
1 SQL Chapter 9 – 8 th edition With help from Chapter 2 – 10 th edition.
Writing Basic SQL SELECT Statements Lecture
Select Complex Queries Database Management Fundamentals LESSON 3.1b.
SQL and Relational Algebra Edel Sherratt Nigel Hardy Horst Holstein.
Chapter 10: Accessing Relational Databases (Self-Study)
Microsoft Office Access 2010 Lab 3
Chapter 6: Set Operators
Writing Basic SQL SELECT Statements
Displaying Query Results
Basic select statement
Group Functions Lab 6.
Using the Set Operators
Basic Queries Specifying Columns
PROC SQL, Overview.
Assignment 2 Due Thursday Feb 9, 2006
Creating Macro Variables in SQL (Review)
David M. Kroenke and David J
20761B 12: Using Set Operators Module 12   Using Set Operators.
Using the Set Operators
Database Queries.
Match-Merge in the Data Step
Noncorrelated subquery
Correlated Subqueries
Restricting and Sorting Data
A more complex example.
Integrity Constraints
Displaying Queries 2 Display a query’s results in a specified order.
Subsetting Rows with the WHERE clause
Outer Joins Inner joins returned only matching rows. When you join tables, you might want to include nonmatching rows as well as matching rows.
Grouping Summary Results
Inner Joins.
Program Testing and Performance
Combining Data Sets in the DATA step.
Summarizing Data with Summary Functions
Writing Basic SQL SELECT Statements
5 The EXCEPT Operator Unique rows from the first result set that are not found in the second result set are selected.
Access/SQL Server Eliminate Duplicates with SELECT DISTINCT
Lab 3 and HRP259 Lab and Combining (with SQL)
Using CASE Value expression
3 Specifying Rows.
Setting SQL Procedure Options
3 Views.
A new keyword -- calculated
Subqueries.
Topic 12 Lesson 2 – Retrieving Data with Queries
SQL set operators and modifiers.
Set Operations Union Intersect Minus.
UNION Operator keywords Displays all rows from both the tables
Remerging Summary Values
Using the Set Operators
Manipulating Data Lesson 3.
Database Programming Using Oracle 11g
Microsoft Access Date.
Presentation transcript:

The INTERSECT Operator 5 The INTERSECT Operator Common unique rows from both result sets are selected.

Flow Diagram: INTERSECT Operator CORR Yes Remove nonmatching columns. No ALL No Yes Remove duplicate rows. Save matching rows. End

Example Data Sets data t1(drop=i) t2(drop=i rename=(z=w)); call streaminit(13453); do i= 1 to 3; x=int(rand("uniform")*5); z=int(rand("uniform")*5); output t1; output t2; end; do i= 4 to 6; run; data t1; set t1 end=done; output; if done then output; data t2; set t2 end=done; if _n_=1 then output; title "t1"; proc print data=t1 noobs;run; title "t2"; proc print data=t2 noobs;run; title;

proc sql; select * from t1 intersect from t2 ; quit;

proc sql; select * from t1 intersect corr from t2 ; quit;

proc sql; select * from t1 intersect all from t2 ; quit;

Orion Star frequently hires experienced Sales staff at higher levels on the assumption that they will be more productive than inexperienced personnel. Create a report that displays the employee identification number of current Level III and Level IV Sales staff hired in 2004, who made at least one sale by the end of 2005. orion.Order_fact table contains information on all sales. orion.Sales table contains information about current Sales employees, including job titles and hire dates.

The INTERSECT Operator Need a query that returns information from rows that exist in both orion.Sales and orion.Order_fact. sales by Sales staff

Create a report that displays the employee identification number of current Level III and Level IV Sales staff hired in 2004, who made at least one sale by the end of 2005. proc sql; select Employee_ID from orion.Sales where year(Hire_date)=2004 and scan(Job_Title,-1) in ("III","IV") intersect all select distinct Employee_ID from orion.Order_fact where year(Order_date) le 2005; quit; s106d08