Submit Search
Upload
Relational Databases - Lecture 4 - SQL language
•
0 likes
•
127 views
Karina Sokolova
Follow
SQL language syntax
Read less
Read more
Technology
Report
Share
Report
Share
1 of 59
Recommended
Introduction to databases
Introduction to databases
Dr Timothy Osadiya CITP., FIfL., ACII
Object Relational Mapping in PHP
Object Relational Mapping in PHP
Rob Knight
Mysql
Mysql
TSUBHASHRI
Oracle SQL AND PL/SQL
Oracle SQL AND PL/SQL
suriyae1
Lift SSIS package to Azure Data Factory V2
Lift SSIS package to Azure Data Factory V2
Manjeet Singh
Sql server basics
Sql server basics
Dilfaroz Khan
Hadoop
Hadoop
yasser hassen
Getting Started with Amazon Redshift
Getting Started with Amazon Redshift
Amazon Web Services
Recommended
Introduction to databases
Introduction to databases
Dr Timothy Osadiya CITP., FIfL., ACII
Object Relational Mapping in PHP
Object Relational Mapping in PHP
Rob Knight
Mysql
Mysql
TSUBHASHRI
Oracle SQL AND PL/SQL
Oracle SQL AND PL/SQL
suriyae1
Lift SSIS package to Azure Data Factory V2
Lift SSIS package to Azure Data Factory V2
Manjeet Singh
Sql server basics
Sql server basics
Dilfaroz Khan
Hadoop
Hadoop
yasser hassen
Getting Started with Amazon Redshift
Getting Started with Amazon Redshift
Amazon Web Services
Batch and Stream Graph Processing with Apache Flink
Batch and Stream Graph Processing with Apache Flink
Vasia Kalavri
Cost-based query optimization in Apache Hive
Cost-based query optimization in Apache Hive
Julian Hyde
Go Programming Patterns
Go Programming Patterns
Hao Chen
Getting started with postgresql
Getting started with postgresql
botsplash.com
Data Lineage with Apache Airflow using Marquez
Data Lineage with Apache Airflow using Marquez
Willy Lulciuc
Oracle_Patching_Untold_Story_Final_Part2.pdf
Oracle_Patching_Untold_Story_Final_Part2.pdf
Alex446314
Vitess: Scalable Database Architecture - Kubernetes Community Days Africa Ap...
Vitess: Scalable Database Architecture - Kubernetes Community Days Africa Ap...
Alkin Tezuysal
Understanding Oracle RAC 11g Release 2 Internals
Understanding Oracle RAC 11g Release 2 Internals
Markus Michalewicz
PLSQL tutorial...
PLSQL tutorial...
JYOTI RANJAN PAL
Snowflake Automated Deployments / CI/CD Pipelines
Snowflake Automated Deployments / CI/CD Pipelines
Drew Hansen
Basic sql Commands
Basic sql Commands
MUHAMMED MASHAHIL PUKKUNNUMMAL
DBA 3 year Interview Questions
DBA 3 year Interview Questions
Naveen P
Trino at linkedIn - 2021
Trino at linkedIn - 2021
Akshay Rai
تصميمات قواعد البيانات
تصميمات قواعد البيانات
hendgamagmail
Masterclass - Redshift
Masterclass - Redshift
Amazon Web Services
Running Apache Spark & Apache Zeppelin in Production
Running Apache Spark & Apache Zeppelin in Production
DataWorks Summit/Hadoop Summit
الوحدة الثالثة - قاعدة البيانات وادارتها
الوحدة الثالثة - قاعدة البيانات وادارتها
Amin Abu Hammad
MySQL for beginners
MySQL for beginners
Saeid Zebardast
NewSQL: The Best of Both "OldSQL" and "NoSQL"
NewSQL: The Best of Both "OldSQL" and "NoSQL"
Sushant Choudhary
MS-SQL SERVER ARCHITECTURE
MS-SQL SERVER ARCHITECTURE
Douglas Bernardini
Relational Databases - Lecture 5 - SQL injection
Relational Databases - Lecture 5 - SQL injection
Karina Sokolova
Relational Databases - Lecture 2 - Entity-relationship diagram
Relational Databases - Lecture 2 - Entity-relationship diagram
Karina Sokolova
More Related Content
What's hot
Batch and Stream Graph Processing with Apache Flink
Batch and Stream Graph Processing with Apache Flink
Vasia Kalavri
Cost-based query optimization in Apache Hive
Cost-based query optimization in Apache Hive
Julian Hyde
Go Programming Patterns
Go Programming Patterns
Hao Chen
Getting started with postgresql
Getting started with postgresql
botsplash.com
Data Lineage with Apache Airflow using Marquez
Data Lineage with Apache Airflow using Marquez
Willy Lulciuc
Oracle_Patching_Untold_Story_Final_Part2.pdf
Oracle_Patching_Untold_Story_Final_Part2.pdf
Alex446314
Vitess: Scalable Database Architecture - Kubernetes Community Days Africa Ap...
Vitess: Scalable Database Architecture - Kubernetes Community Days Africa Ap...
Alkin Tezuysal
Understanding Oracle RAC 11g Release 2 Internals
Understanding Oracle RAC 11g Release 2 Internals
Markus Michalewicz
PLSQL tutorial...
PLSQL tutorial...
JYOTI RANJAN PAL
Snowflake Automated Deployments / CI/CD Pipelines
Snowflake Automated Deployments / CI/CD Pipelines
Drew Hansen
Basic sql Commands
Basic sql Commands
MUHAMMED MASHAHIL PUKKUNNUMMAL
DBA 3 year Interview Questions
DBA 3 year Interview Questions
Naveen P
Trino at linkedIn - 2021
Trino at linkedIn - 2021
Akshay Rai
تصميمات قواعد البيانات
تصميمات قواعد البيانات
hendgamagmail
Masterclass - Redshift
Masterclass - Redshift
Amazon Web Services
Running Apache Spark & Apache Zeppelin in Production
Running Apache Spark & Apache Zeppelin in Production
DataWorks Summit/Hadoop Summit
الوحدة الثالثة - قاعدة البيانات وادارتها
الوحدة الثالثة - قاعدة البيانات وادارتها
Amin Abu Hammad
MySQL for beginners
MySQL for beginners
Saeid Zebardast
NewSQL: The Best of Both "OldSQL" and "NoSQL"
NewSQL: The Best of Both "OldSQL" and "NoSQL"
Sushant Choudhary
MS-SQL SERVER ARCHITECTURE
MS-SQL SERVER ARCHITECTURE
Douglas Bernardini
What's hot
(20)
Batch and Stream Graph Processing with Apache Flink
Batch and Stream Graph Processing with Apache Flink
Cost-based query optimization in Apache Hive
Cost-based query optimization in Apache Hive
Go Programming Patterns
Go Programming Patterns
Getting started with postgresql
Getting started with postgresql
Data Lineage with Apache Airflow using Marquez
Data Lineage with Apache Airflow using Marquez
Oracle_Patching_Untold_Story_Final_Part2.pdf
Oracle_Patching_Untold_Story_Final_Part2.pdf
Vitess: Scalable Database Architecture - Kubernetes Community Days Africa Ap...
Vitess: Scalable Database Architecture - Kubernetes Community Days Africa Ap...
Understanding Oracle RAC 11g Release 2 Internals
Understanding Oracle RAC 11g Release 2 Internals
PLSQL tutorial...
PLSQL tutorial...
Snowflake Automated Deployments / CI/CD Pipelines
Snowflake Automated Deployments / CI/CD Pipelines
Basic sql Commands
Basic sql Commands
DBA 3 year Interview Questions
DBA 3 year Interview Questions
Trino at linkedIn - 2021
Trino at linkedIn - 2021
تصميمات قواعد البيانات
تصميمات قواعد البيانات
Masterclass - Redshift
Masterclass - Redshift
Running Apache Spark & Apache Zeppelin in Production
Running Apache Spark & Apache Zeppelin in Production
الوحدة الثالثة - قاعدة البيانات وادارتها
الوحدة الثالثة - قاعدة البيانات وادارتها
MySQL for beginners
MySQL for beginners
NewSQL: The Best of Both "OldSQL" and "NoSQL"
NewSQL: The Best of Both "OldSQL" and "NoSQL"
MS-SQL SERVER ARCHITECTURE
MS-SQL SERVER ARCHITECTURE
Similar to Relational Databases - Lecture 4 - SQL language
Relational Databases - Lecture 5 - SQL injection
Relational Databases - Lecture 5 - SQL injection
Karina Sokolova
Relational Databases - Lecture 2 - Entity-relationship diagram
Relational Databases - Lecture 2 - Entity-relationship diagram
Karina Sokolova
Relational Databases - Lecture 3 - Logical and physical models (UML)
Relational Databases - Lecture 3 - Logical and physical models (UML)
Karina Sokolova
Relational Databases - Lecture 1 - Introduction
Relational Databases - Lecture 1 - Introduction
Karina Sokolova
shake! 2017 예선 문제 풀이
shake! 2017 예선 문제 풀이
HYUNJEONG KIM
Cdma basics
Cdma basics
uday joshi
Intro to Biodesign: Working with Living Things
Intro to Biodesign: Working with Living Things
Leticia Oxley
Andrew Baum - ArborGen President and CEO
Andrew Baum - ArborGen President and CEO
Arkansas Forestry Association
Not Dead Yet: Designing Great Experiences with Bad Data
Not Dead Yet: Designing Great Experiences with Bad Data
Sonia Koesterer
X1
X1
Maxim Petrov
In-silico study of ToxCast GPCR assays by quantitative structure-activity rel...
In-silico study of ToxCast GPCR assays by quantitative structure-activity rel...
Kamel Mansouri
Similar to Relational Databases - Lecture 4 - SQL language
(11)
Relational Databases - Lecture 5 - SQL injection
Relational Databases - Lecture 5 - SQL injection
Relational Databases - Lecture 2 - Entity-relationship diagram
Relational Databases - Lecture 2 - Entity-relationship diagram
Relational Databases - Lecture 3 - Logical and physical models (UML)
Relational Databases - Lecture 3 - Logical and physical models (UML)
Relational Databases - Lecture 1 - Introduction
Relational Databases - Lecture 1 - Introduction
shake! 2017 예선 문제 풀이
shake! 2017 예선 문제 풀이
Cdma basics
Cdma basics
Intro to Biodesign: Working with Living Things
Intro to Biodesign: Working with Living Things
Andrew Baum - ArborGen President and CEO
Andrew Baum - ArborGen President and CEO
Not Dead Yet: Designing Great Experiences with Bad Data
Not Dead Yet: Designing Great Experiences with Bad Data
X1
X1
In-silico study of ToxCast GPCR assays by quantitative structure-activity rel...
In-silico study of ToxCast GPCR assays by quantitative structure-activity rel...
Recently uploaded
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
gvaughan
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
Slibray Presentation
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
BookNet Canada
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Mark Simos
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
NavinnSomaal
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
BookNet Canada
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
Fwdays
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
Hervé Boutemy
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
BkGupta21
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
Dilum Bandara
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
Alex Barbosa Coqueiro
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
Sergiu Bodiu
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
Florian Wilhelm
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
LoriGlavin3
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
Addepto
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
DianaGray10
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
Raghuram Pandurangan
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
Commit University
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
ScyllaDB
Recently uploaded
(20)
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
Relational Databases - Lecture 4 - SQL language
1.
1 0 0 1 0 1 0 0 1 0 1 0 1 0 0 1 0 0 1 1 0 0 1 0 1 0 1 1 0 1 1 0 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 1 0 1 1 0 1 ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✑ ✑ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✑ ✐ ✐ ✑ ✐ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ ✑ ✐ ✐ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✑ ✑ ✑ ✑ ✐ ✐ ✑ ✑ ✑ ✐ ✐ ✑ ✑ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✑ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✑ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✑ ✑ ✑ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 0 1 0 0 1 ✑ 1 0 0 1 0 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 0 1 1 1 0 1 1 0 0 1 0 1 0 0 1 0 1 1 1 1 0 1 1 0 0 1 0 1 1 1 1 1 1 0 0 0 1 0 1 0 0 1 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 0 0 1 0 1 1 1 1 1 ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✑ Database management SQL
2.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 SQL • Developed in
1970 by IBM as SEQUEL (Structured English QUEry Language) • Structured Query Language • data definition • data manipulation • data control • Based on relational algebra but not strictly following • Helps managing data held in a relational database management system (RDBMS)
3.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Create table CREATE TABLE
Student ( stdId int NOT NULL PRIMARY KEY, unvName varchar(50), stdName varchar(30) NOT NULL, stdSurname varchar(30), stdNat varchar(20) NOT NULL, FOREIGN KEY (unvName) REFERENCES University(unvName) ); CREATE TABLE University ( unvName varchar(50) NOT NULL PRIMARY KEY, unvCountry varchar(20) NOT NULL, unvAddress varchar(90) NOT NULL ); STD_ID: INTEGER UNV_NAME: VARCHAR (50) STD_NAME: VARCHAR (30) STD_SURNAME: VARCHAR (30) STD_NAT: VARCHAR (20) STUDENT UNIVERSITY UNV_NAME: VARCHAR (50) UNV_COUNTRY: VARCHAR (20) UNV_ADDRESS: VARCHAR (90)
4.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Fill in a
table INSERT INTO University VALUES ('UTT', 'France', 'Troyes'), ('PSB', 'France', 'Paris'); INSERT INTO Student VALUES (123, 'UTT', 'Mike', 'Wazowski', 'Polish' ), (345, 'PSB', 'Mary', 'Wazowski', 'Polish' ); STD_ID: INTEGER UNV_NAME: VARCHAR (50) STD_NAME: VARCHAR (30) STD_SURNAME: VARCHAR (30) STD_NAT: VARCHAR (20) STUDENT UNIVERSITY UNV_NAME: VARCHAR (50) UNV_COUNTRY: VARCHAR (20) UNV_ADDRESS: VARCHAR (90)
5.
1 0 0 1 0 1 0 0 1 0 1 0 1 0 0 1 0 0 1 1 0 0 1 0 1 0 1 1 0 1 1 0 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 1 0 1 1 0 1 ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✑ ✑ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✑ ✐ ✐ ✑ ✐ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ ✑ ✐ ✐ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✑ ✑ ✑ ✑ ✐ ✐ ✑ ✑ ✑ ✐ ✐ ✑ ✑ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✑ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✑ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✑ ✑ ✑ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 0 1 0 0 1 ✑ 1 0 0 1 0 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 0 1 1 1 0 1 1 0 0 1 0 1 0 0 1 0 1 1 1 1 0 1 1 0 0 1 0 1 1 1 1 1 1 0 0 0 1 0 1 0 0 1 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 0 0 1 0 1 1 1 1 1 ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✑ Querying language SQL
6.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Set theory Set of
Columns SetofRows
7.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Rules • Sets -
collections of objects • Tables -> smallest logical subset of data • Column -> unique category of information • Row -> must be unique • Order of columns or rows doesn’t matter
8.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Operations on sets Union
A ∪ B Intersection A ∩ B Difference A - B Subset
9.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Basics Subset
10.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Projection • Choose columns
from the full table • The result table have <= attributes than the original
11.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Projection SELECT * FROM database.table1 attribute1
attribute2 attribute3 attribute4 1 ab 12.01 # 2 bc 25.06 @ table1 attribute2 attribute4 ab # bc @ table1 SELECT attribute2, attribute4 FROM table1
12.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Projection SELECT * FROM Student StdId
StdName StdMean StdZip 1 Stan 12.01 10000 2 Marc 18.2 95000 Student mean 12.01 18.2 Temp SELECT StdMean AS mean FROM Student
13.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Projection SELECT * FROM Student StdId
StdName StdMean StdZip 1 Stan 12.01 10000 2 Marc 18.2 95000 Student StdMean*1000 1201 1820 Temp SELECT StdMean * 1000 FROM Student
14.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Restriction • Choose rows
from the full table • The result table have <= tuples than the original • Conditions on attributes: =, >, <, like, in, between, etc. SELECT * FROM database.table1 WHERE condition
15.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Restriction = SELECT StdName FROM
Student WHERE StdZip = 10000 StdId StdName StdMean StdZip 1 Stan 12.01 10000 2 Marc 19.9 95000 3 Mary 18.2 10000 4 Toad 10.8 40000 5 Stan 15.34 10000 6 Franc 13.6 41000 7 Aude 17.9 18000 Student StdName Stan Mary Stan Temp
16.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Restriction BETWEEN SELECT StdName FROM
Student WHERE StdZip BETWEEN 10000 AND 20000 StdId StdName StdMean StdZip 1 Stan 12.01 10000 2 Marc 19.9 95000 3 Mary 18.2 10000 4 Toad 10.8 40000 5 Stan 15.34 10000 6 Franc 13.6 41000 7 Aude 17.9 18000 Student StdName Stan Mary Stan Aude Temp
17.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Restriction LIKE SELECT StdName FROM
Student WHERE StdName LIKE ‘Ma%’ OR StdName LIKE ‘%e’ StdId StdName StdMean StdZip 1 Stan 12.01 10000 2 Marc 19.9 95000 3 Mary 18.2 10000 4 Toad 10.8 40000 5 Stan 15.34 10000 6 Franc 13.6 41000 7 Aude 17.9 18000 Student StdName Marc Mary Aude Temp
18.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Duplicates SELECT DISTINCT StdName FROM
Student WHERE StdZip = 10000 StdId StdName StdMean StdZip 1 Stan 12.01 10000 2 Marc 19.9 95000 3 Mary 18.2 10000 4 Toad 10.8 40000 5 Stan 15.34 10000 6 Franc 13.6 41000 7 Aude 17.9 18000 Student StdName Stan Mary Temp
19.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 NULL SELECT StdName FROM Student WHERE
StdMean IS null StdId StdName StdMean StdZip 1 Stan 12.01 10000 2 Marc NULL 95000 3 Mary NULL 10000 4 Toad 10.8 40000 5 Stan 15.34 10000 6 Franc 13.6 41000 7 Aude NULL 18000 Student StdName Marc Mary Aude Temp
20.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Order • The results
are not ordered • ORDER BY attribute is used to order the result • The default order is ASC - ascending (or alphabetical) • Add DESC to make in descending
21.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Order by SELECT DISTINCT
StdZip FROM Student ORDER BY StdZip ASC StdId StdName StdMean StdZip 1 Stan 12.01 10000 2 Marc 19.9 95000 3 Mary 18.2 10000 4 Toad 10.8 40000 5 Stan 15.34 10000 6 Franc 13.6 41000 7 Aude 17.9 18000 Student StdZip 10000 18000 40000 41000 95000 Temp
22.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Order by SELECT DISTINCT
StdZip FROM Student ORDER BY StdZip DESC StdId StdName StdMean StdZip 1 Stan 12.01 10000 2 Marc 19.9 95000 3 Mary 18.2 10000 4 Toad 10.8 40000 5 Stan 15.34 10000 6 Franc 13.6 41000 7 Aude 17.9 18000 Student StdZip 95000 41000 40000 18000 10000 Temp
23.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Limit SELECT DISTINCT StdZip FROM
Student ORDER BY StdZip DESC LIMIT 3 StdId StdName StdMean StdZip 1 Stan 12.01 10000 2 Marc 19.9 95000 3 Mary 18.2 10000 4 Toad 10.8 40000 5 Stan 15.34 10000 6 Franc 13.6 41000 7 Aude 17.9 18000 Student StdZip 95000 41000 40000 Temp
24.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Aggregation • MIN, MAX,
SUM, AVG, COUNT • SELECT min(attribute) • FROM table • WHERE condition • Group by columns • Having condition
25.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Min SELECT MIN(StdMean) FROM Student StdId
StdName StdMean StdZip 1 Stan 12.01 10000 2 Marc 19.9 95000 3 Mary 18.2 10000 4 Toad 10.8 40000 5 Stan 15.34 10000 6 Franc 13.6 41000 7 Aude 17.9 18000 Student min(Mean) 10.8 Temp
26.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Count SELECT COUNT(StudentID) FROM Apply WHERE
University = ‘UTT’ StudentID Date University 123 2013 UTT 234 2015 UTT 123 2014 UTT 678 2016 PSB 345 2015 UTT 234 2015 EPF 123 2013 EPF Apply count(StudentID) 4 Temp
27.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Count distinct StudentID Date
University 123 2013 UTT 234 2015 UTT 123 2014 UTT 678 2016 PSB 345 2015 UTT 234 2015 EPF 123 2013 EPF Apply count(StudentID) 3 Temp SELECT COUNT(distinct StudentID) FROM Apply WHERE University = ‘UTT’
28.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Count by StudentID Date
University 123 2013 UTT 234 2015 UTT 123 2014 UTT 678 2016 PSB 345 2015 UTT 234 2015 EPF 123 2013 EPF Apply University student UTT 3 PSB 1 EPF 2 Temp SELECT University, COUNT(distinct StudentID) as student FROM Apply GROUP BY University
29.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Count by StudentID Date
University 123 2013 UTT 234 2015 UTT 123 2014 UTT 678 2016 PSB 345 2015 UTT 234 2015 EPF 123 2013 EPF Apply University student id UTT 3 234 PSB 1 678 EPF 2 123 Temp SELECT University, COUNT(distinct StudentID) as student, StudentID as id FROM Apply GROUP BY University Random
30.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Having StudentID Date University 123
2013 UTT 234 2015 UTT 123 2014 UTT 678 2016 PSB 345 2015 UTT 234 2015 EPF 123 2013 EPF Apply University PSB EPF Temp SELECT University FROM Apply GROUP BY University HAVING count(*) < 4
31.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Combine relations
32.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Cartesian product • Obtain
all combinations of two sets a b c d x y a x a y b x b y c x c y d x d y { { { { } } } } {
33.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Cartesian product SELECT StdName,
UnvName FROM Student, University StdId StdName StdMean StdZip 1 Stan 12.01 10000 2 Marc 19.9 95000 3 Mary 18.2 10000 Student StdName UnvName Stan PSB Marc UTT Mary PSB Stan UTT Marc PSB Mary UTT Temp UnvId UnvName UnvLocation 1 PSB Paris 2 UTT Troyes University
34.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Join • Combine tuples
of two tables based on certain condition
35.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Simple Join EmpId Name 1
Stan 2 Marc 3 Mary Employee ParentId Name Age 1 Sara 7 1 Amy 10 3 Pole 2Child Employee.Name Child.Name Stan Sara Stan Amy Mary Pole Temp { { SELECT e.Name, c.Name FROM Employee e, Child c WHERE e.EmpId = c.ParentId
36.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Inner Join EmpId Name 1
Stan 2 Marc 3 Mary Employee ParentId Name Age 1 Sara 7 1 Amy 10 3 Pole 2Child Employee.Name Child.Name Stan Sara Stan Amy Mary Pole Temp { { SELECT Employee.Name, Child.Name FROM Employee INNER JOIN Child ON EmpId = ParentId
37.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Join EmpId Name 1 Stan 2
Marc 3 Mary Employee ParentId Name Age 1 Sara 7 1 Amy 10 3 Pole 2Child Employee.Name Child.Name Stan Sara Stan Amy Mary Pole Temp { { SELECT Employee.Name, Child.Name FROM Employee JOIN Child ON EmpId = ParentId
38.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Natural Join ParentId ParentName 1
Stan 2 Marc 3 Mary Employee ParentId ChildName Age 1 Sara 7 1 Amy 10 3 Pole 2Child ParentName ChildName Stan Sara Stan Amy Mary Pole Temp { { SELECT ParentName, ChildName FROM Employee NATURAL JOIN Child key is found automatically
39.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Natural Join ParentId ParentName 1
Stan 2 Marc 3 Mary Employee ParentId ChildName Age 1 Sara 7 1 Amy 10 3 Pole 2Child ParentName ChildName Stan Sara Stan Amy Mary Pole Temp { { SELECT ParentName, ChildName FROM Employee JOIN Child USING(ParentId) good practice to define a key
40.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Simple Join StdId StdName
StdZip 1 Stan 10000 2 Marc 95000 3 Mary 10000Student UnvId UnvName UnvLocation 1 PSB Paris 2 UTT Troyes 3 EPF TroyesUniversity StdId UnvId Date 1 1 01.01.15 2 2 05.05.15 3 1 14.03.15Apply StdName UnvName Stan PSB Mary PSB Temp { { {{ SELECT StdName, UnvName FROM Student, Apply, University WHERE Student.StdId=ApplyStdID AND University.UnvID=Apply.UnvID AND Apply.UnvId=1
41.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Simple Join StdId StdName
StdZip 1 Stan 10000 2 Marc 95000 3 Mary 10000Student UnvId UnvName UnvLocation 1 PSB Paris 2 UTT Troyes 3 EPF TroyesUniversity StdId UnvId Date 1 1 01.01.15 2 2 05.05.15 3 1 14.03.15Apply StdName UnvName Stan PSB Mary PSB Temp { { {{ SELECT StdName, UnvName FROM Student JOIN Apply ON Student.StdId=Apply.StdID JOIN University ON University.UnvID=Apply.UnvID WHERE Apply.UnvId=1
42.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Self Join • Combine
tuples of two tables based on certain condition • Used when the same type of information presented as two attributes • Classical example: employee and its manager id name surname manager 1 John Smith 3 2 Mike Wazowski 3 3 Bill Gates NULL 4 Crazy Frog 2 Employee
43.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Self Join id name
surname manager 1 John Smith 3 2 Mike Wazowski 3 3 Bill Gates NULL 4 Crazy Frog 2 name surname m.name m.surname John Smith Bill Gates Mike Wazowski Bill Gates Crazy Frog Mike Wazowski SELECT e1.name, e1.surname, e2.name as m.name, e2.surname as m.surname FROM Employee e1, Employee e2 WHERE e1.manager = e2.id Employee
44.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Join
45.
1 0 0 1 0 1 0 0 1 0 1 0 1 0 0 1 0 0 1 1 0 0 1 0 1 0 1 1 0 1 1 0 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 1 0 1 ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✑ ✑ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✑ ✐ ✐ ✑ ✐ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ ✑ ✐ ✐ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✑ ✑ ✑ ✑ ✐ ✐ ✑ ✑ ✑ ✐ ✐ ✑ ✑ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✑ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✑ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✑ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 0 1 0 0 1 ✑ 0 0 1 0 0 1 0 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 0 1 1 1 0 1 1 0 0 1 0 1 0 0 1 0 1 1 1 1 0 1 1 0 0 1 0 1 1 1 1 1 1 0 0 0 1 0 1 0 0 1 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 0 0 1 0 1 1 1 1 1 ✑ ✐ ✐ ✑ ✑ Create and query
46.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Sets and subqueries
47.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Intersect • Returns only
common tuples of two queries • Removes duplicate rows from the final result set • Two results must: • Have the same number of attributes • Have attributes of the same type
48.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Intersect SELECT * FROM sales2015 INTERSECT SELECT
* FROM sales2016 Person Amount Alex 1000 Piter 3000 Mary 500 Aude 5600 Person Amount Alex 5000 Piter 3000 John 3500 Aude 5600 Person Amount Piter 3000 Aude 5600 sales2015 sales2016 temp
49.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Intersect ALL SELECT person,
amount FROM sales2015 INTERSECT ALL SELECT person, amount FROM sales2016 id person amount 1 Alex 1000 2 Piter 3000 3 Mary 500 4 Aude 5600 id person amount 1 Piter 3000 2 Piter 3000 3 John 3500 4 Aude 5600 person amount Piter 3000 Aude 5600 Piter 3000 sales2015 sales2016 temp
50.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 IN SELECT * FROM sales2015 WHERE
person IN ( SELECT person FROM sales2016 ) Person Amount Alex 1000 Piter 3000 Mary 500 Aude 5600 Person Amount Alex 5000 Piter 3000 John 3500 Aude 5600 Person Amount Piter 3000 Aude 5600 Alex 1000 sales2015 sales2016 temp
51.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 EXISTS SELECT person, amount FROM
sales2015 s1 WHERE EXISTS (SELECT * FROM sales2016 s2 WHERE s2.person=s1.person) id person amount 1 Alex 1000 2 Piter 3000 3 Mary 500 4 Aude 5600 id person amount 1 Piter 3000 2 Piter 3000 3 John 3500 4 Aude 5600 person amount Piter 3000 Aude 5600 sales2015 sales2016 temp
52.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Except • Returns tuples
all tuples from the first query that are not present in the second query • EXCEPT ALL does not remove duplicate rows from the final result • Two results must: • Have the same number of attributes • Have attributes of the same type
53.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Except SELECT * FROM sales2015 EXCEPT SELECT
* FROM sales2016 Person Amount Alex 1000 Piter 3000 Mary 500 Aude 5600 Person Amount Alex 5000 Piter 3000 John 3500 Aude 5600 Person Amount Alex 1000 Mary 500 sales2015 sales2016 temp
54.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 NOT IN SELECT * FROM
sales2015 WHERE person IN ( SELECT person FROM sales2016 ) Person Amount Alex 1000 Piter 3000 Mary 500 Aude 5600 Person Amount Alex 5000 Piter 3000 John 3500 Aude 5600 Person Amount Mary 500 sales2015 sales2016 temp
55.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 NOT EXISTS SELECT person,
amount FROM sales2015 s1 WHERE NOT EXISTS (SELECT * FROM sales2016 s2 WHERE s2.person=s1.person) id person amount 1 Alex 1000 2 Piter 3000 3 Mary 500 4 Aude 5600 id person amount 1 Piter 3000 2 Piter 3000 3 John 3500 4 Aude 5600 person amount Alex 1000 Mary 500 sales2015 sales2016 temp
56.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Union • Combine the
results of two queries into one • Two results must: • Have the same number of attributes • Have attributes of the same type
57.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Union SELECT * FROM sales2015 UNION SELECT
* FROM sales2016 Person Amount Alex 1000 Piter 3000 Mary 500 Aude 5600 Person Amount Alex 5000 Piter 3000 John 3500 Aude 5600 Person Amount Alex 5000 Piter 3000 John 3500 Aude 5600 Alex 1000 Mary 500 sales2015 sales2016 temp
58.
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 ✑ ✑ 1 ✑ ✑ 1 0 1 Union ALL SELECT * FROM
sales2015 UNION ALL SELECT * FROM sales2016 Person Amount Alex 1000 Piter 3000 Mary 500 Aude 5600 Person Amount Alex 5000 Piter 3000 John 3500 Aude 5600 Person Amount Alex 5000 Piter 3000 John 3500 Aude 5600 Alex 1000 Piter 3000 Mary 500 Aude 5600sales2015 sales2016 temp
59.
1 0 0 1 0 1 0 0 1 0 1 0 1 0 0 1 0 0 1 1 0 0 1 0 1 0 1 1 0 1 1 0 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 1 0 1 ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✑ ✑ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✑ ✐ ✐ ✑ ✐ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ ✑ ✐ ✐ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✑ ✑ ✑ ✑ ✐ ✐ ✑ ✑ ✑ ✐ ✐ ✑ ✑ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✑ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✑ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✑ ✑ ✐ ✑ ✐ ✑ ✐ ✐ ✑ ✐ ✐ ✑ ✐ ✑ ✑ 0 1 0 0 1 ✑ 0 0 1 0 0 1 0 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 0 1 1 1 0 1 1 0 0 1 0 1 0 0 1 0 1 1 1 1 0 1 1 0 0 1 0 1 1 1 1 1 1 0 0 0 1 0 1 0 0 1 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 0 0 1 0 1 1 1 1 1 ✑ ✐ ✐ ✑ ✑ Queries