SlideShare a Scribd company logo
Part I – simple queries

Database Design and Development: A
Visual Approach © 2006 Prentice Hall

Chapter 9
Sky_Member Database

Exhibit 9-1: Sky_Member Database Data Model
Creating a Query

1

2

Exhibit 9-2: Creating a Query
The Design View

1

2

Exhibit 9-3: The Design View
The SQL View
1

2

Exhibit 9-4: Selecting the SQL View for a Query
SQL Equivalent of a Query

Exhibit 9-5: The SQL View for a Query
SQL Select All Columns and Rows

Exhibit 9-6: Analysis of the Select Statement Retrieving All Columns and Rows
Selecting Explicit Columns

Exhibit 9-7: Query with an Explicit Column List
SQL: Selecting Explicit Columns

Exhibit 9-8: The Analysis of the Select Statement with an Explicit Column List
Sorting

Exhibit 9-9: Designing a Query with Sorting
Analysis: Sorting

Exhibit 9-10a: Select Statement with Order by
Clause, BEFORE sorting
Analysis: Sorting

Exhibit 9-10b: Select Statement with Order by
Clause
Multiple Column Sort

Exhibit 9-11: Design of a Query with Multiple Sort Columns
Analysis: Multiple Column Sort

Exhibit 9-12: Analysis of Sorting by Multiple Columns
Analysis: Multiple Column Sort

Exhibit 9-12: Analysis of Sorting by Multiple
Columns
Conditional Operators

Exhibit 9-13: Conditional Operators
SQL: Where Clause

Exhibit 9-14: Entering a Criterion for a Column
Analysis: Where Clause Query

Exhibit 9-15: Analysis of Query with a
Where Clause
Analysis: Where Clause Query

Exhibit 9-15: Analysis of Query with a
Where Clause
Text Column Conditions

Exhibit 9-16: Designing a Query with a Condition
Involving a Text Column
Linking Conditions with AND

Conditions: jumps > 10 AND skill = ‘I’

Exhibit 9-18: Multiple Conditions Linked
with an AND
Linking Conditions with OR

Conditions: jumps > 10 OR skill = ‘I’

Exhibit 9-19: Multiple Conditions Linked
with an OR
Query Using AND

Exhibit 9-20: Combining Two Conditions
with an AND
Analysis: Query Using AND

Exhibit 9-21: The Analysis of the Query Using an
AND Relationship
Analysis: Query Using AND

Exhibit 9-21: The Analysis of the Query Using an
AND Relationship
Analysis: Query Using AND

Exhibit 9-21: The Analysis of the Query Using an
AND Relationship
Query Using OR

Exhibit 9-22: Combining Two Conditions
with an OR
Analysis: Query Using OR

Exhibit 9-23: The Analysis of the Query Using an
OR Relationship
Analysis: Query Using OR

Exhibit 9-23: The Analysis of the Query Using an
OR Relationship
Conditions on the Same Column

Exhibit 9-24: Using the AND Operator to Select
Based on a Range of Values
Analysis: Conditions on the Same Column

Exhibit 9-25: The Analysis of the Query
Jumps > 10 and Jumps < 20
Analysis: Conditions on the Same Column

Exhibit 9-25: The Analysis of the Query
Jumps > 10 and Jumps < 20
Analysis: Conditions on the Same Column

Exhibit 9-25: The Analysis of the Query
Jumps > 10 and Jumps < 20
Between Operator

Exhibit 9-28: Using the Between Operator
Analysis: Between Operator

Exhibit 9-29: Analysis of the Query Using
Between
Conditions on Same Column with OR

Exhibit 9-26: Using OR to Enter Multiple
Criteria on the Same Column
Combining AND and OR Incorrectly

Exhibit 9-30: Incorrectly Combining AND
and OR
SQL: Incorrectly Combining AND and OR

Exhibit 9-31: Analysis of the Query Incorrectly
Combining AND and OR
Analysis: Incorrectly Combining AND and OR

Exhibit 9-31: Analysis of the Query Incorrectly
Combining AND and OR
Analysis: Incorrectly Combining AND and OR

Exhibit 9-31: Analysis of the Query Incorrectly
Combining AND and OR
Correctly Combining AND and OR

Exhibit 9-32: Correctly Combining AND and OR
SQL: Correctly Combining AND and OR

Exhibit 9-33: The Analysis of the Query
Correctly Combining AND and OR
SQL: Correctly Combining AND and OR

Exhibit 9-33: The Analysis of the Query
Correctly Combining AND and OR
SQL: Correctly Combining AND and OR

Exhibit 9-33: The Analysis of the Query
Correctly Combining AND and OR
Aggregate Functions

Exhibit 9-34: Commonly Used Aggregate
Functions
Summing the Number of Jumps

Aggregate functions result in the display of a single value.
Exhibit 9-35: A Query that Sums the Number of Jumps
SQL: Sum Function

Exhibit 9-36: Analysis of the Query that Sums
the Number of Jumps
Analysis: Sum Function

Exhibit 9-36: Analysis of the Query that Sums
the Number of Jumps
Analysis: Using Where with Sum

Exhibit 9-37: Analysis of the Query that Uses
Sum with Where
Analysis: Using Where with Sum

Exhibit 9-37: Analysis of the Query that Uses
Sum with Where
Analysis: Using Where with Sum

Exhibit 9-37: Analysis of the Query that Uses
Sum with Where
Repeated Values
SELECT skill
FROM sky_member;

If you want to know the possible skills in the Member table,
this query lists them multiple times.
Exhibit 9-38: Selecting Skills
Using DISTINCT
SELECT DISTINCT skill
FROM sky_member

Distinct eliminates duplicate rows from the display.

Exhibit 9-39: Selecting Skills Using Distinct
Using GROUP BY
SELECT
FROM
GROUP BY

skill, Avg(jumps) AS ‘AverageJumps’
sky_member
skill;

Exhibit 9-41: The Design for the Query
Using Group By
Analysis: GROUP BY

Exhibit 9-42: The Analysis for the Query Using
Group By
Analysis: GROUP BY

Exhibit 9-42: The Analysis for the Query Using
Group By
Analysis: GROUP BY

Exhibit 9-42: The Analysis for the Query Using
Group By
Incorrect Use of GROUP BY
SELECT
FROM

skill, Avg(jumps) AS ‘AverageJumps’
sky_member;

GROUP BY must be used, and the same column must be used in the
GROUP BY and the aggregate function.

Exhibit 9-40: Error Generated by missing
GROUP BY specification
GROUP BY and HAVING
SELECT skill,
Avg(jumps) AS ‘AverageJumps’
FROM sky_member
GROUP BY skill
HAVING Avg(jumps) < 20

Having eliminates aggregations
that do not meet the conditions.

Exhibit 9-43: The Design for the Query
Using Having
Analysis: HAVING Clause

Exhibit 9-44: The Analysis for the Query Using
Having
Analysis: HAVING Clause

Exhibit 9-44: The Analysis for the Query Using
Having
Analysis: HAVING Clause

Exhibit 9-44: The Analysis for the Query Using
Having
HAVING and WHERE
SELECT skill,
Avg(jumps) AS ‘AverageJumps’
FROM sky_member
WHERE equip = ‘Y’
GROUP BY skill
HAVING Avg(jumps) > 10

Exhibit 9-45: Results for the Query Using
Having and Where
Analysis: HAVING and WHERE

Exhibit 9-46: The Analysis for the Query Using
Having and Where
Analysis: HAVING and WHERE

Exhibit 9-46: The Analysis for the Query Using
Having and Where
Analysis: HAVING and WHERE

Exhibit 9-46: The Analysis for the Query Using
Having and Where

More Related Content

Similar to Lab 2 slides

D80194GC20_sg1.pdf
D80194GC20_sg1.pdfD80194GC20_sg1.pdf
D80194GC20_sg1.pdf
Edris Fedlu
 
Sql ch 13 - sql-views
Sql ch 13 - sql-viewsSql ch 13 - sql-views
Sql ch 13 - sql-views
Mukesh Tekwani
 
Les12[1]Creating Views
Les12[1]Creating ViewsLes12[1]Creating Views
Les12[1]Creating Views
siavosh kaviani
 
Advanced tips of dbms statas
Advanced tips of dbms statasAdvanced tips of dbms statas
Advanced tips of dbms statasLouis liu
 
Chapter 07 ddl_sql
Chapter 07 ddl_sqlChapter 07 ddl_sql
Chapter 07 ddl_sql
Nazir Ahmed
 
Oracle 11g
Oracle 11gOracle 11g
Oracle 11g
firstlogichelpdesk
 
OLAP Basics and Fundamentals by Bharat Kalia
OLAP Basics and Fundamentals by Bharat Kalia OLAP Basics and Fundamentals by Bharat Kalia
OLAP Basics and Fundamentals by Bharat Kalia
Bharat Kalia
 
Create flexible React applications using GraphQL apis
Create flexible React applications using GraphQL apisCreate flexible React applications using GraphQL apis
Create flexible React applications using GraphQL apis
Maurice De Beijer [MVP]
 
Creating Views - oracle database
Creating Views - oracle databaseCreating Views - oracle database
Creating Views - oracle database
Salman Memon
 
YABench: A Comprehensive Framework for RDF Stream Processor Correctness and P...
YABench: A Comprehensive Framework for RDF Stream Processor Correctness and P...YABench: A Comprehensive Framework for RDF Stream Processor Correctness and P...
YABench: A Comprehensive Framework for RDF Stream Processor Correctness and P...
Maxim Kolchin
 
Intro to Data warehousing Lecture 06
Intro to Data warehousing   Lecture 06Intro to Data warehousing   Lecture 06
Intro to Data warehousing Lecture 06
AnwarrChaudary
 
How to Implement Distributed Data Store
How to Implement Distributed Data Store How to Implement Distributed Data Store
How to Implement Distributed Data Store
Philip Zhong
 
Cross-Project Build Co-change Prediction
Cross-Project Build Co-change PredictionCross-Project Build Co-change Prediction
Cross-Project Build Co-change Prediction
Shane McIntosh
 
Les10
Les10Les10
284566820 1 z0-061(1)
284566820 1 z0-061(1)284566820 1 z0-061(1)
284566820 1 z0-061(1)
panagara
 
12c SQL Plan Directives
12c SQL Plan Directives12c SQL Plan Directives
12c SQL Plan Directives
Franck Pachot
 
Competition 1 (blog 1)
Competition 1 (blog 1)Competition 1 (blog 1)
Competition 1 (blog 1)
TarunPaparaju
 
Chapter15
Chapter15Chapter15
Chapter15
gourab87
 
ACQSurvey (Poster)
ACQSurvey (Poster)ACQSurvey (Poster)
ACQSurvey (Poster)
Hossein A. (Saeed) Rahmani
 

Similar to Lab 2 slides (20)

Toc Sg
Toc SgToc Sg
Toc Sg
 
D80194GC20_sg1.pdf
D80194GC20_sg1.pdfD80194GC20_sg1.pdf
D80194GC20_sg1.pdf
 
Sql ch 13 - sql-views
Sql ch 13 - sql-viewsSql ch 13 - sql-views
Sql ch 13 - sql-views
 
Les12[1]Creating Views
Les12[1]Creating ViewsLes12[1]Creating Views
Les12[1]Creating Views
 
Advanced tips of dbms statas
Advanced tips of dbms statasAdvanced tips of dbms statas
Advanced tips of dbms statas
 
Chapter 07 ddl_sql
Chapter 07 ddl_sqlChapter 07 ddl_sql
Chapter 07 ddl_sql
 
Oracle 11g
Oracle 11gOracle 11g
Oracle 11g
 
OLAP Basics and Fundamentals by Bharat Kalia
OLAP Basics and Fundamentals by Bharat Kalia OLAP Basics and Fundamentals by Bharat Kalia
OLAP Basics and Fundamentals by Bharat Kalia
 
Create flexible React applications using GraphQL apis
Create flexible React applications using GraphQL apisCreate flexible React applications using GraphQL apis
Create flexible React applications using GraphQL apis
 
Creating Views - oracle database
Creating Views - oracle databaseCreating Views - oracle database
Creating Views - oracle database
 
YABench: A Comprehensive Framework for RDF Stream Processor Correctness and P...
YABench: A Comprehensive Framework for RDF Stream Processor Correctness and P...YABench: A Comprehensive Framework for RDF Stream Processor Correctness and P...
YABench: A Comprehensive Framework for RDF Stream Processor Correctness and P...
 
Intro to Data warehousing Lecture 06
Intro to Data warehousing   Lecture 06Intro to Data warehousing   Lecture 06
Intro to Data warehousing Lecture 06
 
How to Implement Distributed Data Store
How to Implement Distributed Data Store How to Implement Distributed Data Store
How to Implement Distributed Data Store
 
Cross-Project Build Co-change Prediction
Cross-Project Build Co-change PredictionCross-Project Build Co-change Prediction
Cross-Project Build Co-change Prediction
 
Les10
Les10Les10
Les10
 
284566820 1 z0-061(1)
284566820 1 z0-061(1)284566820 1 z0-061(1)
284566820 1 z0-061(1)
 
12c SQL Plan Directives
12c SQL Plan Directives12c SQL Plan Directives
12c SQL Plan Directives
 
Competition 1 (blog 1)
Competition 1 (blog 1)Competition 1 (blog 1)
Competition 1 (blog 1)
 
Chapter15
Chapter15Chapter15
Chapter15
 
ACQSurvey (Poster)
ACQSurvey (Poster)ACQSurvey (Poster)
ACQSurvey (Poster)
 

Recently uploaded

The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
Jen Stirrup
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 

Recently uploaded (20)

The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 

Lab 2 slides