SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (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
 

Andere mochten auch

Taggerfm Artist 091116
Taggerfm Artist 091116Taggerfm Artist 091116
Taggerfm Artist 091116
Tim Rootsaert
 
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
 

Andere mochten auch (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...
 

Ähnlich wie SQL202.2 Accelerated Introduction to SQL Using SQL Server Module 2

Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic Concepts
Tony 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-republic
Kaing Menglieng
 
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
Kaing Menglieng
 
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
 

Ähnlich wie 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)
 

Mehr von Dan D'Urso

Course Catalog
Course CatalogCourse Catalog
Course Catalog
Dan D'Urso
 

Mehr von 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
 

Kürzlich hochgeladen

Kürzlich hochgeladen (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

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]