SlideShare una empresa de Scribd logo
1 de 68
SQL200 SQL Programming Workshop 2 – Joins, Subqueries, Unions, Calculations and Grouping Bookstore SQL200  Module 2 Based on  SQL Clearly Explained  by Jan Harrington
Note on SQL200 Slides ,[object Object],[object Object],[object Object],Bookstore SQL200  Module 2
Warning! ,[object Object],Bookstore SQL200  Module 2 New Name Old Name Orders Order_filled Order_Lines Orderlines
SQL200 Contact Information Bookstore SQL200  Module 2 P.O. Box 6142 Laguna Niguel, CA 92607 949-489-1472 http://www.d2associates.com [email_address]   Copyright 2001-20011 All rights reserved.
SQL200 Resources ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Bookstore SQL200  Module 2
SQL200 SQL Programming Part 1 – Joins Bookstore SQL200  Module 2
Bookstore SQL200  Module 2 Relational Database with constraints (from text)
More conventions ,[object Object],[object Object],[object Object],Bookstore SQL200  Module 2
Joins ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Bookstore SQL200  Module 2
Bookstore SQL200  Module 2
Inner Join ,[object Object],[object Object],[object Object],Bookstore SQL200  Module 2
Inner Join Bookstore SQL200  Module 2 Older Syntax: Select <column-list> From <tablelist> Where <predicate> Still very commonly used
Inner Join Bookstore SQL200  Module 2 Example using older syntax: SELECT  customer_first_name, customer_street, order_numb, order_date from  customers, orders Where  customers.customer_numb = orders.customer_numb
Inner Join with Result Bookstore SQL200  Module 2
Inner Join (New Syntax) Bookstore SQL200  Module 2 Basic SQL 92 Syntax: Select <column-list> From <table1> Inner join <table2> On <join condition>
Inner Join Bookstore SQL200  Module 2 Basic Example: SELECT  customer_first_name, customer_street, order_numb, order_date from  customers inner join  orders on  customers.customer_numb = orders.customer_numb
Inner Join with Result Bookstore SQL200  Module 2
Inner Join over Multiple columns ,[object Object],[object Object],Bookstore SQL200  Module 2
Bookstore SQL200  Module 2 Inner Join Result in MS Access
Inner Join ,[object Object],[object Object],[object Object],[object Object],[object Object],Bookstore SQL200  Module 2
Cross Join ,[object Object],[object Object],[object Object],Bookstore SQL200  Module 2
Bookstore SQL200  Module 2 Cross Join Result Set in MS Access
Additional SQL92 Syntax ,[object Object],[object Object],[object Object],Bookstore SQL200  Module 2
Joining More than Two Tables ,[object Object],[object Object],[object Object],[object Object],Bookstore SQL200  Module 2
Joining More than Two Tables ,[object Object],Bookstore SQL200  Module 2 SELECT customer_first_name, customer_street, orders.order_numb, orders.order_date, orderlines.isbn, orderlines.quantity FROM customers INNER JOIN orders ON customers.customer_numb=orders.customer_numb INNER JOIN orderlines on orders.order_numb = orderlines.order_numb
Multi-table Join with Results Bookstore SQL200  Module 2
On Your Own ,[object Object],[object Object],Bookstore SQL200  Module 2
Sample Database ,[object Object],[object Object],Bookstore SQL200  Module 2
Correlation Names (Table Aliases) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Bookstore SQL200  Module 2
Self Joins ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Bookstore SQL200  Module 2
Self Joins Bookstore SQL200  Module 2 SELECT e.*, m.name FROM employees AS e, employees AS m WHERE e.managerid = m.employeeid;
Bookstore SQL200  Module 2
Outer Joins ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Bookstore SQL200  Module 2
Left Outer Join Bookstore SQL200  Module 2 Basic SQL 92 Syntax: Select <column-list> From <table1> Left join <table2> On <join condition>
Left-Join Bookstore SQL200  Module 2 Basic Example: SELECT customer_first_name, customer_street, order_numb, order_date from customers as c left join orders as o on c.customer_numb = o.customer_numb
Bookstore SQL200  Module 2
Left Join with Results Bookstore SQL200  Module 2
SQL200 SQL Programming Part 2– Subqueries, Unions Bookstore SQL200  Module 2
Subqueries ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Bookstore SQL200  Module 2
Uncorrelated Subquery Bookstore SQL200  Module 2 select isbn, quantity from orderlines where order_numb in  (select order_numb from orders where order_date between ‘1/1/99’ and ‘12/31/99’);
Uncorrelated Subquery with Results Bookstore SQL200  Module 2
Negative Subquery ,[object Object],Bookstore SQL200  Module 2
Negative Subquery Bookstore SQL200  Module 2 select isbn, quantity from orderlines where order_numb not in  (select order_numb from orders where order_date between ‘1/1/99’ and ‘12/31/99’);
Negative Subquery with Results Bookstore SQL200  Module 2
Correlated Subquery with Exists ,[object Object],[object Object],[object Object],Bookstore SQL200  Module 2
Correlated subquery with Exists Bookstore SQL200  Module 2 SELECT isbn, quantity FROM orderlines AS ol WHERE exists  (select * from orders o where ol.order_numb = o.order_numb and o.order_date between ‘1/1/99’ and ‘12/31/99’); This type of query covered in intermediate SQL class
Unions ,[object Object],[object Object],Bookstore SQL200  Module 2
Unions Bookstore SQL200  Module 2 Select <column-list> from <table1> Union [ALL] Select <same-columns> from <table2>
Unions Bookstore SQL200  Module 2 select * from employees union all select * from employees_copy
Bookstore SQL200  Module 2 Results of Union query
SQL200 SQL Programming Part 3 – Calculations, Aggregates Bookstore SQL200  Module 2
Calculated Fields ,[object Object],Bookstore SQL200  Module 2 SELECT order_numb, quantity, cost_each,  quantity*cost_each as extension FROM orderlines
Calculated field in the Result Bookstore SQL200  Module 2
Bookstore SQL200  Module 2
String Manipulation ,[object Object],[object Object],[object Object],[object Object],[object Object],Bookstore SQL200  Module 2
Concatenation ,[object Object],[object Object],Bookstore SQL200  Module 2 Basic syntax: (Access) Field1 & Field2 (Oracle, std) Field1 || Field2 (Sql Server) Field1 + Field2
Concatenation Bookstore SQL200  Module 2 select customer_first_name + ‘ ‘ + trim(customer_last_name) as Name from customers
Bookstore SQL200  Module 2
Date Functions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Bookstore SQL200  Module 2
Aggregate Functions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Bookstore SQL200  Module 2
Aggregate Functions Bookstore SQL200  Module 2 Basic syntax: Select <function>(<column>) From <table> Group by <column-list> Having <predicate> Group by all columns to left of one(s) you want to aggregate
Aggregate Functions Bookstore SQL200  Module 2 SELECT order_numb, Count(*) AS [Number of Order Lines] , Sum(quantity) AS [Total Quantity], Sum(quantity * cost_each) AS [Total Amount] FROM order_lines GROUP BY order_numb having count(*)  > 1;
Bookstore SQL200  Module 2
Having vs. Where ,[object Object],[object Object],[object Object],Bookstore SQL200  Module 2
Exercise ,[object Object],[object Object],[object Object],[object Object],[object Object],Bookstore SQL200  Module 2
Exercise Result Bookstore SQL200  Module 2 [end module]
Notes Bookstore SQL200  Module 2
Notes Bookstore SQL200  Module 2

Más contenido relacionado

La actualidad más candente

Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQLSql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQLPrashant Kumar
 
14 22 size sql book(1)
14 22 size sql book(1)14 22 size sql book(1)
14 22 size sql book(1)bhganesh
 
AVB202 Intermediate Microsoft Access VBA
AVB202 Intermediate Microsoft Access VBAAVB202 Intermediate Microsoft Access VBA
AVB202 Intermediate Microsoft Access VBADan D'Urso
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studioAravindharamanan S
 
Partitioning on Oracle 12c - What changed on the most important Oracle feature
Partitioning on Oracle 12c - What changed on the most important Oracle featurePartitioning on Oracle 12c - What changed on the most important Oracle feature
Partitioning on Oracle 12c - What changed on the most important Oracle featureLuis Marques
 
Sql clauses by Manan Pasricha
Sql clauses by Manan PasrichaSql clauses by Manan Pasricha
Sql clauses by Manan PasrichaMananPasricha
 
SQL Tutorial for BCA-2
SQL Tutorial for BCA-2SQL Tutorial for BCA-2
SQL Tutorial for BCA-2Raj vardhan
 
Download 11-incredible-excel-conditional-formatting-tricks
Download 11-incredible-excel-conditional-formatting-tricksDownload 11-incredible-excel-conditional-formatting-tricks
Download 11-incredible-excel-conditional-formatting-tricksKarthikeyan Natarajan
 
CIS 336 Inspiring Innovation -- cis336.com
CIS 336 Inspiring Innovation -- cis336.comCIS 336 Inspiring Innovation -- cis336.com
CIS 336 Inspiring Innovation -- cis336.comkopiko105
 
Cis 336 Enhance teaching / snaptutorial.com
Cis 336    Enhance teaching / snaptutorial.comCis 336    Enhance teaching / snaptutorial.com
Cis 336 Enhance teaching / snaptutorial.comDavis104
 
AIN102.2 Microsoft Access Queries
AIN102.2 Microsoft Access QueriesAIN102.2 Microsoft Access Queries
AIN102.2 Microsoft Access QueriesDan D'Urso
 
CIS 336 Achievement Education --cis336.com
CIS 336 Achievement Education --cis336.comCIS 336 Achievement Education --cis336.com
CIS 336 Achievement Education --cis336.comagathachristie171
 
CIS336 Education for Service--cis336.com
CIS336 Education for Service--cis336.comCIS336 Education for Service--cis336.com
CIS336 Education for Service--cis336.comwilliamwordsworth11
 
CIS 336 Redefined Education--cis336.com
CIS 336 Redefined Education--cis336.comCIS 336 Redefined Education--cis336.com
CIS 336 Redefined Education--cis336.comagathachristie208
 
CIS 336 PAPERS Education for Service--cis336papers.com
CIS 336 PAPERS Education for Service--cis336papers.comCIS 336 PAPERS Education for Service--cis336papers.com
CIS 336 PAPERS Education for Service--cis336papers.comKeatonJennings14
 

La actualidad más candente (20)

Sql Tuning
Sql TuningSql Tuning
Sql Tuning
 
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQLSql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
 
14 22 size sql book(1)
14 22 size sql book(1)14 22 size sql book(1)
14 22 size sql book(1)
 
Fg d
Fg dFg d
Fg d
 
Sql
SqlSql
Sql
 
DBMS
DBMSDBMS
DBMS
 
AVB202 Intermediate Microsoft Access VBA
AVB202 Intermediate Microsoft Access VBAAVB202 Intermediate Microsoft Access VBA
AVB202 Intermediate Microsoft Access VBA
 
Sql joins
Sql joinsSql joins
Sql joins
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
 
Partitioning on Oracle 12c - What changed on the most important Oracle feature
Partitioning on Oracle 12c - What changed on the most important Oracle featurePartitioning on Oracle 12c - What changed on the most important Oracle feature
Partitioning on Oracle 12c - What changed on the most important Oracle feature
 
Sql clauses by Manan Pasricha
Sql clauses by Manan PasrichaSql clauses by Manan Pasricha
Sql clauses by Manan Pasricha
 
SQL Tutorial for BCA-2
SQL Tutorial for BCA-2SQL Tutorial for BCA-2
SQL Tutorial for BCA-2
 
Download 11-incredible-excel-conditional-formatting-tricks
Download 11-incredible-excel-conditional-formatting-tricksDownload 11-incredible-excel-conditional-formatting-tricks
Download 11-incredible-excel-conditional-formatting-tricks
 
CIS 336 Inspiring Innovation -- cis336.com
CIS 336 Inspiring Innovation -- cis336.comCIS 336 Inspiring Innovation -- cis336.com
CIS 336 Inspiring Innovation -- cis336.com
 
Cis 336 Enhance teaching / snaptutorial.com
Cis 336    Enhance teaching / snaptutorial.comCis 336    Enhance teaching / snaptutorial.com
Cis 336 Enhance teaching / snaptutorial.com
 
AIN102.2 Microsoft Access Queries
AIN102.2 Microsoft Access QueriesAIN102.2 Microsoft Access Queries
AIN102.2 Microsoft Access Queries
 
CIS 336 Achievement Education --cis336.com
CIS 336 Achievement Education --cis336.comCIS 336 Achievement Education --cis336.com
CIS 336 Achievement Education --cis336.com
 
CIS336 Education for Service--cis336.com
CIS336 Education for Service--cis336.comCIS336 Education for Service--cis336.com
CIS336 Education for Service--cis336.com
 
CIS 336 Redefined Education--cis336.com
CIS 336 Redefined Education--cis336.comCIS 336 Redefined Education--cis336.com
CIS 336 Redefined Education--cis336.com
 
CIS 336 PAPERS Education for Service--cis336papers.com
CIS 336 PAPERS Education for Service--cis336papers.comCIS 336 PAPERS Education for Service--cis336papers.com
CIS 336 PAPERS Education for Service--cis336papers.com
 

Destacado

Technical stream presentation
Technical stream presentationTechnical stream presentation
Technical stream presentationDynistics
 
Sub query_SQL
Sub query_SQLSub query_SQL
Sub query_SQLCoT
 
Microsoft SQL Server PowerPivot
Microsoft SQL Server PowerPivotMicrosoft SQL Server PowerPivot
Microsoft SQL Server PowerPivotMark Ginnebaugh
 
T-SQL: Pivot, Unpivot, Except, Intersect
T-SQL: Pivot, Unpivot, Except, IntersectT-SQL: Pivot, Unpivot, Except, Intersect
T-SQL: Pivot, Unpivot, Except, IntersectBill Lin
 
SQL302 Intermediate SQL Workshop 1
SQL302 Intermediate SQL Workshop 1SQL302 Intermediate SQL Workshop 1
SQL302 Intermediate SQL Workshop 1Dan D'Urso
 
George Washington Teacher’s Institute
George Washington Teacher’s InstituteGeorge Washington Teacher’s Institute
George Washington Teacher’s Institutemoorebl
 
AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1guest38bf
 
Taggerfm Artist 091116
Taggerfm Artist 091116Taggerfm Artist 091116
Taggerfm Artist 091116Tim Rootsaert
 
eParticipation in The Netherlands
eParticipation in The NetherlandseParticipation in The Netherlands
eParticipation in The NetherlandsBZK
 
Inspraakpunt Overheid20
Inspraakpunt   Overheid20Inspraakpunt   Overheid20
Inspraakpunt Overheid20BZK
 
Ikregeer Overheid20
Ikregeer   Overheid20Ikregeer   Overheid20
Ikregeer Overheid20BZK
 
Producing the Investigative Report
Producing the Investigative ReportProducing the Investigative Report
Producing the Investigative ReportRyan Thornburg
 
AMP110 Microsoft Access Macros
AMP110 Microsoft Access MacrosAMP110 Microsoft Access Macros
AMP110 Microsoft Access MacrosDan D'Urso
 
The Future-Present Interrelationship: Reflections, Thoughts, And Ideas, As We...
The Future-Present Interrelationship: Reflections, Thoughts, And Ideas, As We...The Future-Present Interrelationship: Reflections, Thoughts, And Ideas, As We...
The Future-Present Interrelationship: Reflections, Thoughts, And Ideas, As We...Andres Agostini, Future Knowledgist
 

Destacado (20)

Technical stream presentation
Technical stream presentationTechnical stream presentation
Technical stream presentation
 
Pivot Unpivot
Pivot UnpivotPivot Unpivot
Pivot Unpivot
 
Using T-SQL
Using T-SQL Using T-SQL
Using T-SQL
 
Sub query_SQL
Sub query_SQLSub query_SQL
Sub query_SQL
 
Microsoft SQL Server PowerPivot
Microsoft SQL Server PowerPivotMicrosoft SQL Server PowerPivot
Microsoft SQL Server PowerPivot
 
T-SQL: Pivot, Unpivot, Except, Intersect
T-SQL: Pivot, Unpivot, Except, IntersectT-SQL: Pivot, Unpivot, Except, Intersect
T-SQL: Pivot, Unpivot, Except, Intersect
 
SQL Data Manipulation
SQL Data ManipulationSQL Data Manipulation
SQL Data Manipulation
 
SQL subquery
SQL subquerySQL subquery
SQL subquery
 
Sql subquery
Sql  subquerySql  subquery
Sql subquery
 
SQL302 Intermediate SQL Workshop 1
SQL302 Intermediate SQL Workshop 1SQL302 Intermediate SQL Workshop 1
SQL302 Intermediate SQL Workshop 1
 
George Washington Teacher’s Institute
George Washington Teacher’s InstituteGeorge Washington Teacher’s Institute
George Washington Teacher’s Institute
 
AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1
 
Taggerfm Artist 091116
Taggerfm Artist 091116Taggerfm Artist 091116
Taggerfm Artist 091116
 
eParticipation in The Netherlands
eParticipation in The NetherlandseParticipation in The Netherlands
eParticipation in The Netherlands
 
Inspraakpunt Overheid20
Inspraakpunt   Overheid20Inspraakpunt   Overheid20
Inspraakpunt Overheid20
 
Ikregeer Overheid20
Ikregeer   Overheid20Ikregeer   Overheid20
Ikregeer Overheid20
 
Fi
FiFi
Fi
 
Producing the Investigative Report
Producing the Investigative ReportProducing the Investigative Report
Producing the Investigative Report
 
AMP110 Microsoft Access Macros
AMP110 Microsoft Access MacrosAMP110 Microsoft Access Macros
AMP110 Microsoft Access Macros
 
The Future-Present Interrelationship: Reflections, Thoughts, And Ideas, As We...
The Future-Present Interrelationship: Reflections, Thoughts, And Ideas, As We...The Future-Present Interrelationship: Reflections, Thoughts, And Ideas, As We...
The Future-Present Interrelationship: Reflections, Thoughts, And Ideas, As We...
 

Similar a SQL202.2 Accelerated Introduction to SQL Using SQL Server Module 2

SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3
SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3
SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3Dan D'Urso
 
SQL202.1 Accelerated Introduction to SQL Using SQL Server Module 1
SQL202.1 Accelerated Introduction to SQL Using SQL Server Module 1SQL202.1 Accelerated Introduction to SQL Using SQL Server Module 1
SQL202.1 Accelerated Introduction to SQL Using SQL Server Module 1Dan D'Urso
 
SQL200.3 Module 3
SQL200.3 Module 3SQL200.3 Module 3
SQL200.3 Module 3Dan D'Urso
 
SQL200.2 Module 2
SQL200.2 Module 2SQL200.2 Module 2
SQL200.2 Module 2Dan D'Urso
 
SQL302 Intermediate SQL Workshop 2
SQL302 Intermediate SQL Workshop 2SQL302 Intermediate SQL Workshop 2
SQL302 Intermediate SQL Workshop 2Dan D'Urso
 
Dms 22319 micro project
Dms 22319 micro projectDms 22319 micro project
Dms 22319 micro projectARVIND SARDAR
 
SQL212.1 Introduction to SQL using Oracle Module 1
SQL212.1 Introduction to SQL using Oracle Module 1SQL212.1 Introduction to SQL using Oracle Module 1
SQL212.1 Introduction to SQL using Oracle Module 1Dan D'Urso
 
Die Neuheiten in MariaDB 10.2 und MaxScale 2.1
Die Neuheiten in MariaDB 10.2 und MaxScale 2.1Die Neuheiten in MariaDB 10.2 und MaxScale 2.1
Die Neuheiten in MariaDB 10.2 und MaxScale 2.1MariaDB plc
 
Performance tuning
Performance tuningPerformance tuning
Performance tuningami111
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic ConceptsTony Wong
 
Understand when to use user defined functions in sql server tech-republic
Understand when to use user defined functions in sql server   tech-republicUnderstand when to use user defined functions in sql server   tech-republic
Understand when to use user defined functions in sql server tech-republicKaing Menglieng
 
SQL302 Intermediate SQL Workshop 3
SQL302 Intermediate SQL Workshop 3SQL302 Intermediate SQL Workshop 3
SQL302 Intermediate SQL Workshop 3Dan D'Urso
 
Avoiding cursors with sql server 2005 tech republic
Avoiding cursors with sql server 2005   tech republicAvoiding cursors with sql server 2005   tech republic
Avoiding cursors with sql server 2005 tech republicKaing Menglieng
 
SQL/MX 3.6 Select for update feature
SQL/MX 3.6 Select for update featureSQL/MX 3.6 Select for update feature
SQL/MX 3.6 Select for update featureFrans Jongma
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxBhupendraShahi6
 
Statements,joins and operators in sql by thanveer danish melayi(1)
Statements,joins and operators in sql by thanveer danish melayi(1)Statements,joins and operators in sql by thanveer danish melayi(1)
Statements,joins and operators in sql by thanveer danish melayi(1)Muhammed Thanveer M
 

Similar a SQL202.2 Accelerated Introduction to SQL Using SQL Server Module 2 (20)

SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3
SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3
SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3
 
SQL202.1 Accelerated Introduction to SQL Using SQL Server Module 1
SQL202.1 Accelerated Introduction to SQL Using SQL Server Module 1SQL202.1 Accelerated Introduction to SQL Using SQL Server Module 1
SQL202.1 Accelerated Introduction to SQL Using SQL Server Module 1
 
SQL200.3 Module 3
SQL200.3 Module 3SQL200.3 Module 3
SQL200.3 Module 3
 
SQL200.2 Module 2
SQL200.2 Module 2SQL200.2 Module 2
SQL200.2 Module 2
 
SQL302 Intermediate SQL Workshop 2
SQL302 Intermediate SQL Workshop 2SQL302 Intermediate SQL Workshop 2
SQL302 Intermediate SQL Workshop 2
 
Adbms
AdbmsAdbms
Adbms
 
Dms 22319 micro project
Dms 22319 micro projectDms 22319 micro project
Dms 22319 micro project
 
SQL212.1 Introduction to SQL using Oracle Module 1
SQL212.1 Introduction to SQL using Oracle Module 1SQL212.1 Introduction to SQL using Oracle Module 1
SQL212.1 Introduction to SQL using Oracle Module 1
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
Die Neuheiten in MariaDB 10.2 und MaxScale 2.1
Die Neuheiten in MariaDB 10.2 und MaxScale 2.1Die Neuheiten in MariaDB 10.2 und MaxScale 2.1
Die Neuheiten in MariaDB 10.2 und MaxScale 2.1
 
Performance tuning
Performance tuningPerformance tuning
Performance tuning
 
SQL Tunning
SQL TunningSQL Tunning
SQL Tunning
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic Concepts
 
Understand when to use user defined functions in sql server tech-republic
Understand when to use user defined functions in sql server   tech-republicUnderstand when to use user defined functions in sql server   tech-republic
Understand when to use user defined functions in sql server tech-republic
 
SQL302 Intermediate SQL Workshop 3
SQL302 Intermediate SQL Workshop 3SQL302 Intermediate SQL Workshop 3
SQL302 Intermediate SQL Workshop 3
 
Avoiding cursors with sql server 2005 tech republic
Avoiding cursors with sql server 2005   tech republicAvoiding cursors with sql server 2005   tech republic
Avoiding cursors with sql server 2005 tech republic
 
Sq lite
Sq liteSq lite
Sq lite
 
SQL/MX 3.6 Select for update feature
SQL/MX 3.6 Select for update featureSQL/MX 3.6 Select for update feature
SQL/MX 3.6 Select for update feature
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
 
Statements,joins and operators in sql by thanveer danish melayi(1)
Statements,joins and operators in sql by thanveer danish melayi(1)Statements,joins and operators in sql by thanveer danish melayi(1)
Statements,joins and operators in sql by thanveer danish melayi(1)
 

Más de Dan D'Urso

SQL201S Accelerated Introduction to MySQL Queries
SQL201S Accelerated Introduction to MySQL QueriesSQL201S Accelerated Introduction to MySQL Queries
SQL201S Accelerated Introduction to MySQL QueriesDan D'Urso
 
LCD201d Database Diagramming with Lucidchart
LCD201d Database Diagramming with LucidchartLCD201d Database Diagramming with Lucidchart
LCD201d Database Diagramming with LucidchartDan D'Urso
 
Database Normalization
Database NormalizationDatabase Normalization
Database NormalizationDan D'Urso
 
VIS201d Visio Database Diagramming
VIS201d Visio Database DiagrammingVIS201d Visio Database Diagramming
VIS201d Visio Database DiagrammingDan D'Urso
 
PRJ101a Project 2013 Accelerated
PRJ101a Project 2013 AcceleratedPRJ101a Project 2013 Accelerated
PRJ101a Project 2013 AcceleratedDan D'Urso
 
PRJ101xl Project Libre Basic Training
PRJ101xl Project Libre Basic TrainingPRJ101xl Project Libre Basic Training
PRJ101xl Project Libre Basic TrainingDan D'Urso
 
Introduction to coding using Python
Introduction to coding using PythonIntroduction to coding using Python
Introduction to coding using PythonDan D'Urso
 
Stem conference
Stem conferenceStem conference
Stem conferenceDan D'Urso
 
SQL200A Microsoft Access SQL Design
SQL200A Microsoft Access SQL DesignSQL200A Microsoft Access SQL Design
SQL200A Microsoft Access SQL DesignDan D'Urso
 
Microsoft access self joins
Microsoft access self joinsMicrosoft access self joins
Microsoft access self joinsDan D'Urso
 
SQL302 Intermediate SQL
SQL302 Intermediate SQLSQL302 Intermediate SQL
SQL302 Intermediate SQLDan D'Urso
 
AIN106 Access Reporting and Analysis
AIN106 Access Reporting and AnalysisAIN106 Access Reporting and Analysis
AIN106 Access Reporting and AnalysisDan D'Urso
 
Course Catalog
Course CatalogCourse Catalog
Course CatalogDan D'Urso
 
SQL212 Oracle SQL Manual
SQL212 Oracle SQL ManualSQL212 Oracle SQL Manual
SQL212 Oracle SQL ManualDan D'Urso
 
SQL201W MySQL SQL Manual
SQL201W MySQL SQL ManualSQL201W MySQL SQL Manual
SQL201W MySQL SQL ManualDan D'Urso
 
SQL206 SQL Median
SQL206 SQL MedianSQL206 SQL Median
SQL206 SQL MedianDan D'Urso
 
SQL202 SQL Server SQL Manual
SQL202 SQL Server SQL ManualSQL202 SQL Server SQL Manual
SQL202 SQL Server SQL ManualDan D'Urso
 
AIN102 Microsoft Access Queries
AIN102 Microsoft Access QueriesAIN102 Microsoft Access Queries
AIN102 Microsoft Access QueriesDan D'Urso
 
AIN102S Access string function sample queries
AIN102S Access string function sample queriesAIN102S Access string function sample queries
AIN102S Access string function sample queriesDan D'Urso
 

Más de Dan D'Urso (20)

SQL201S Accelerated Introduction to MySQL Queries
SQL201S Accelerated Introduction to MySQL QueriesSQL201S Accelerated Introduction to MySQL Queries
SQL201S Accelerated Introduction to MySQL Queries
 
LCD201d Database Diagramming with Lucidchart
LCD201d Database Diagramming with LucidchartLCD201d Database Diagramming with Lucidchart
LCD201d Database Diagramming with Lucidchart
 
Database Normalization
Database NormalizationDatabase Normalization
Database Normalization
 
VIS201d Visio Database Diagramming
VIS201d Visio Database DiagrammingVIS201d Visio Database Diagramming
VIS201d Visio Database Diagramming
 
PRJ101a Project 2013 Accelerated
PRJ101a Project 2013 AcceleratedPRJ101a Project 2013 Accelerated
PRJ101a Project 2013 Accelerated
 
PRJ101xl Project Libre Basic Training
PRJ101xl Project Libre Basic TrainingPRJ101xl Project Libre Basic Training
PRJ101xl Project Libre Basic Training
 
Introduction to coding using Python
Introduction to coding using PythonIntroduction to coding using Python
Introduction to coding using Python
 
Stem conference
Stem conferenceStem conference
Stem conference
 
SQL200A Microsoft Access SQL Design
SQL200A Microsoft Access SQL DesignSQL200A Microsoft Access SQL Design
SQL200A Microsoft Access SQL Design
 
Microsoft access self joins
Microsoft access self joinsMicrosoft access self joins
Microsoft access self joins
 
SQL302 Intermediate SQL
SQL302 Intermediate SQLSQL302 Intermediate SQL
SQL302 Intermediate SQL
 
AIN106 Access Reporting and Analysis
AIN106 Access Reporting and AnalysisAIN106 Access Reporting and Analysis
AIN106 Access Reporting and Analysis
 
Course Catalog
Course CatalogCourse Catalog
Course Catalog
 
SQL212 Oracle SQL Manual
SQL212 Oracle SQL ManualSQL212 Oracle SQL Manual
SQL212 Oracle SQL Manual
 
SQL201W MySQL SQL Manual
SQL201W MySQL SQL ManualSQL201W MySQL SQL Manual
SQL201W MySQL SQL Manual
 
AIN100
AIN100AIN100
AIN100
 
SQL206 SQL Median
SQL206 SQL MedianSQL206 SQL Median
SQL206 SQL Median
 
SQL202 SQL Server SQL Manual
SQL202 SQL Server SQL ManualSQL202 SQL Server SQL Manual
SQL202 SQL Server SQL Manual
 
AIN102 Microsoft Access Queries
AIN102 Microsoft Access QueriesAIN102 Microsoft Access Queries
AIN102 Microsoft Access Queries
 
AIN102S Access string function sample queries
AIN102S Access string function sample queriesAIN102S Access string function sample queries
AIN102S Access string function sample queries
 

Último

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 

Último (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 

SQL202.2 Accelerated Introduction to SQL Using SQL Server Module 2

  • 1. SQL200 SQL Programming Workshop 2 – Joins, Subqueries, Unions, Calculations and Grouping Bookstore SQL200 Module 2 Based on SQL Clearly Explained by Jan Harrington
  • 2.
  • 3.
  • 4. SQL200 Contact Information Bookstore SQL200 Module 2 P.O. Box 6142 Laguna Niguel, CA 92607 949-489-1472 http://www.d2associates.com [email_address] Copyright 2001-20011 All rights reserved.
  • 5.
  • 6. SQL200 SQL Programming Part 1 – Joins Bookstore SQL200 Module 2
  • 7. Bookstore SQL200 Module 2 Relational Database with constraints (from text)
  • 8.
  • 9.
  • 10. Bookstore SQL200 Module 2
  • 11.
  • 12. Inner Join Bookstore SQL200 Module 2 Older Syntax: Select <column-list> From <tablelist> Where <predicate> Still very commonly used
  • 13. Inner Join Bookstore SQL200 Module 2 Example using older syntax: SELECT customer_first_name, customer_street, order_numb, order_date from customers, orders Where customers.customer_numb = orders.customer_numb
  • 14. Inner Join with Result Bookstore SQL200 Module 2
  • 15. Inner Join (New Syntax) Bookstore SQL200 Module 2 Basic SQL 92 Syntax: Select <column-list> From <table1> Inner join <table2> On <join condition>
  • 16. Inner Join Bookstore SQL200 Module 2 Basic Example: SELECT customer_first_name, customer_street, order_numb, order_date from customers inner join orders on customers.customer_numb = orders.customer_numb
  • 17. Inner Join with Result Bookstore SQL200 Module 2
  • 18.
  • 19. Bookstore SQL200 Module 2 Inner Join Result in MS Access
  • 20.
  • 21.
  • 22. Bookstore SQL200 Module 2 Cross Join Result Set in MS Access
  • 23.
  • 24.
  • 25.
  • 26. Multi-table Join with Results Bookstore SQL200 Module 2
  • 27.
  • 28.
  • 29.
  • 30.
  • 31. Self Joins Bookstore SQL200 Module 2 SELECT e.*, m.name FROM employees AS e, employees AS m WHERE e.managerid = m.employeeid;
  • 32. Bookstore SQL200 Module 2
  • 33.
  • 34. Left Outer Join Bookstore SQL200 Module 2 Basic SQL 92 Syntax: Select <column-list> From <table1> Left join <table2> On <join condition>
  • 35. Left-Join Bookstore SQL200 Module 2 Basic Example: SELECT customer_first_name, customer_street, order_numb, order_date from customers as c left join orders as o on c.customer_numb = o.customer_numb
  • 36. Bookstore SQL200 Module 2
  • 37. Left Join with Results Bookstore SQL200 Module 2
  • 38. SQL200 SQL Programming Part 2– Subqueries, Unions Bookstore SQL200 Module 2
  • 39.
  • 40. Uncorrelated Subquery Bookstore SQL200 Module 2 select isbn, quantity from orderlines where order_numb in (select order_numb from orders where order_date between ‘1/1/99’ and ‘12/31/99’);
  • 41. Uncorrelated Subquery with Results Bookstore SQL200 Module 2
  • 42.
  • 43. Negative Subquery Bookstore SQL200 Module 2 select isbn, quantity from orderlines where order_numb not in (select order_numb from orders where order_date between ‘1/1/99’ and ‘12/31/99’);
  • 44. Negative Subquery with Results Bookstore SQL200 Module 2
  • 45.
  • 46. Correlated subquery with Exists Bookstore SQL200 Module 2 SELECT isbn, quantity FROM orderlines AS ol WHERE exists (select * from orders o where ol.order_numb = o.order_numb and o.order_date between ‘1/1/99’ and ‘12/31/99’); This type of query covered in intermediate SQL class
  • 47.
  • 48. Unions Bookstore SQL200 Module 2 Select <column-list> from <table1> Union [ALL] Select <same-columns> from <table2>
  • 49. Unions Bookstore SQL200 Module 2 select * from employees union all select * from employees_copy
  • 50. Bookstore SQL200 Module 2 Results of Union query
  • 51. SQL200 SQL Programming Part 3 – Calculations, Aggregates Bookstore SQL200 Module 2
  • 52.
  • 53. Calculated field in the Result Bookstore SQL200 Module 2
  • 54. Bookstore SQL200 Module 2
  • 55.
  • 56.
  • 57. Concatenation Bookstore SQL200 Module 2 select customer_first_name + ‘ ‘ + trim(customer_last_name) as Name from customers
  • 58. Bookstore SQL200 Module 2
  • 59.
  • 60.
  • 61. Aggregate Functions Bookstore SQL200 Module 2 Basic syntax: Select <function>(<column>) From <table> Group by <column-list> Having <predicate> Group by all columns to left of one(s) you want to aggregate
  • 62. Aggregate Functions Bookstore SQL200 Module 2 SELECT order_numb, Count(*) AS [Number of Order Lines] , Sum(quantity) AS [Total Quantity], Sum(quantity * cost_each) AS [Total Amount] FROM order_lines GROUP BY order_numb having count(*) > 1;
  • 63. Bookstore SQL200 Module 2
  • 64.
  • 65.
  • 66. Exercise Result Bookstore SQL200 Module 2 [end module]