SlideShare a Scribd company logo
1 of 44
SQL
SQL is a standard language for accessing databases.
SQL stands for Structured Query Language.
Using SQL you can
execute queries against a database
retrieve data from a database
insert, update and delete records in a database
SQL can create new databases and tables
SQL SELECT
SELECT Forename, Surname FROM Students;
SQL SELECT
SELECT Forename, Surname FROM Students;
SQL SELECT
SELECT Forename, Surname FROM Students
WHERE TutorGroup = ‘2T1’;
SQL SELECT
SELECT Forename, Surname FROM Students
WHERE TutorGroup = ‘2T1’;
SQL SELECT – OR
SELECT Forename, Surname FROM Students
WHERE TutorGroup = ‘3R1’
OR TutorGroup = ‘3R2’;
SQL SELECT – OR
SELECT Forename, Surname FROM Students
WHERE TutorGroup = ‘3R1’
OR TutorGroup = ‘3R2’;
SQL SELECT – AND
SELECT Forename, Surname FROM Students
WHERE Forename = ‘Stephen’
AND TutorGroup = ‘3R1’;
SQL SELECT – AND
SELECT Forename, Surname FROM Students
WHERE Forename = ‘Stephen’
AND TutorGroup = ‘3R1’;
SQL SELECT *
SELECT * FROM Students
WHERE Surname = ‘French’;
SQL SELECT *
SELECT * FROM Students
WHERE Surname = ‘French’;
SQL SELECT – COMPARISONS
Can use >, <, = comparison operators:
SELECT * FROM Students
WHERE Age >= 14 and Age <=17;
Can also use BETWEEN:
SELECT * FROM Students
WHERE Surname BETWEEN ‘Langley’ AND ‘Jones’;
SQL SELECT ORDER BY
SELECT Forename, Surname FROM Students
ORDER BY Surname;
SQL SELECT ORDER BY
SELECT Forename, Surname FROM Students
ORDER BY Surname;
SQL SELECT ORDER BY DESC
SELECT Forename, Surname FROM Students
ORDER BY Surname DESC;
SQL SELECT ORDER BY DESC
SELECT Forename, Surname FROM Students
ORDER BY Surname DESC;
SQL INSERT INTO
INSERT INTO Students (CandidateNumber, Forename, Surname, DOB,
TutorGroup)
VALUES (07551881’, ‘Aisha’, ‘Obeke’, ‘08/03/01’, 2T2’);
SQL INSERT INTO
INSERT INTO Students (CandidateNumber, Forename, Surname, DOB,
TutorGroup)
VALUES (07551881’, ‘Aisha’, ‘Obeke’, ‘08/03/01’, 2T2’);
SQL UPDATE
UPDATE Students
SET TutorGroup TO ‘2T2’
WHERE CandidateNumber = ‘07541120’;
SQL UPDATE
UPDATE Students
SET TutorGroup TO ‘2T2’
WHERE CandidateNumber = ‘07541120’;
SQL DELETE
DELETE FROM Students
WHERE CandidateNumber = ‘07743612’;
SQL DELETE
DELETE FROM Students
WHERE CandidateNumber = ‘07743612’;
Wildcards
A wildcard character is used to replace one or more
characters in a string.
Wildcards are useful in situations when incomplete
information is available.
A LIKE operator is used with a wildcard.
Two different wildcards that can be used:
% (the percent symbol) is used to represent zero, one
or multiple characters.
_ (the underscore symbol) is used to represent a single
character.
(Access uses an astrisk (*) rather than a % and a question
mark (?) rather than _)
Wildcard examples
Example Purpose
WHERE surname LIKE ‘Thom%’ Used to find any values in the surname
field that start with “Thom”
WHERE surname LIKE ‘%son’ Used to find any values in the surname
field that end with “son”
WHERE surname LIKE ‘%is%’ Used to find any values that have “is”
anywhere in the surname field.
WHERE surname LIKE ‘_h%’ Used to find any values in the surname
field that have “h” as the second
character.
WHERE surname LIKE ‘m % %’ Used to find any vlues in the surname
field that start with “m” and have at
least 3 characters.
WHERE surname LIKE ‘a%Z’ Used to find any values in the surname
field that start with “a” and end with
“z”.
Wildcard example
Example 1
Used to search the database to display the name,
swimming pool details, resort and resort type of any
hotel in a coastal resort that starts with the letter ‘A’.
SELECT hotelName, swimmingPool, resortName, resortType
FROM Hotel, Resort
WHERE Hotel.resortID = Resort.resortID AND resortName
LIKE ‘A*’ AND resortType = ‘coastal’;
Wildcard example
Example 2
Used to display the customer’s full name, booking number, start date,
hotel name and resort name of all customers who has an ‘h’ as the
second letter of their surname. These details should be listed in
alphabetical orger of surname: customers within the same surname
should be listed so that the customer with the earliest holiday should be
listed first.
SELECT firstname, surname, bookingNo, hotelName, resortName,
startDate
FROM Customer, Booking, Hotel, Resort
WHERE Customer.[customer#]=Booking.[customer#] AND
Booking.hotelRef=Hotel.hotelRef AND Hotel.resortID=Resort.resortID
AND surname LIKE ‘?h*’
ORDER BY surname ASC, startDate ASC;
Wildcards
SELECT Forename, Surname FROM Students
WHERE TutorGroup LIKE= ‘3%’;
Wildcards
SELECT Forename, Surname FROM Students
WHERE TutorGroup LIKE= ‘3%’;
Wildcards
SELECT Forename, Surname FROM Students
WHERE TutorGroup LIKE= ‘%T%’;
Wildcards
SELECT Forename, Surname FROM Students
WHERE TutorGroup LIKE= ‘%T%’;
SQL INNER JOIN
SELECT Orders.OrderID, Customers.CustomerName
FROM Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID
Two tables, Orders and Customers
Customer.CustomerID is PK in Customers table
Orders.CustomerID is FK in Orders table
SQL INNER JOIN
SELECT Orders.OrderID, Customers.CustomerName
FROM Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID
Aggregate Functions
Aggregate functions operate on a set of rows to return
a single, statistical value. You apply an aggregate to a
set of rows, which may be:
All the rows in a table
Only those rows specified by a WHERE clause
Those rows created by a GROUP BY clause (see later)
Aggregate Functions
Function Description
AVG ( ) Returns the average value of a numeric column or
expression
COUNT ( ) Returns the number rows that match the criteria in the
WHERE clause.
MAX ( ) Returns the largest value of the selected column or
expression
MIN ( ) Returns the smallest value of the selected column or
expression.
SUM ( ) Returns the total sum of a numeric column or expressions.
The most common aggregate functions used are listed below:
Examples
Uses readable headings to display the cheapest and
dearest price per night.
Used to display the average number of nights booked.
SELECT MIN(pricePersonNight) AS [Cheapest Price per Night],
MAX(pricePersonNight) AS [Dearest Price perNight]
FROM Hotel;
SELECT ROUND(AVG(numberNights),2)
FROM Booking;
Examples
Used to display a list of the different types of resort
together with the number of resorts in each of those
categories.
Uses a readable heading to display the total number
of people booked into a hotel in July.
SELECT resortType, COUNT (*)
FROM Resort
GROUP BY resortType;
SELECT SUM(numberInParty) AS [People on holiday in July]
FROM Booking
WHERE startDate LIKE ‘*/07/*’;
Arithmetic Expressions
Arithmetic expressions can be used to compute
values as part of a SELECT query. The arithmetic
expressions can contain column names, numeric
numbers and arithmetic operators.
An Alias can be used to give any column in an answer
table a temporary name.
Examples
The query below will display the name, price,
quantity and cost of each product in a specified order.
Executing the query produces the answer table below:
SELECT productName AS ['Product Name'], price,
quantity, price*quantity
FROM Product, Order
WHERE Product.productID = [Order].productID AND order#
- 123456;
We can make the table more readable by using an
alias:
Executing the query produces the answer table below:
SELECT productName AS ['Product Name'], price,
quantity, price*quantity AS ['Product Cost']
FROM Product, Order
WHERE Product.productID = [Order].productID AND order#
= 123456;
Group by
The GROUP BY clause is used in a SELECT to form
sets (or goups) of records. It does this by gathering
together all the records that have identical data in the
specified column.
Example
The query below is used to display a list of products
categories together with the dearest product in each
of those categories. The category with the cheapest
product is listed first.
Example
Use to display the number of bookings for hotels in
coastal resorts. Show the resort type and use a
readable heading for the results returned by the
aggregate function.
Example
Use to display a list of each type of meal plan together
with the number of bookings made for each of those
meal plans. The details should be listed from the least
popular meal plan to the most popular.

More Related Content

What's hot

06.01 sql select distinct
06.01 sql select distinct06.01 sql select distinct
06.01 sql select distinctBishal Ghimire
 
Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)Vidyasagar Mundroy
 
Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)Achmad Solichin
 
Obtain better data accuracy using reference tables
Obtain better data accuracy using reference tablesObtain better data accuracy using reference tables
Obtain better data accuracy using reference tablesKiran Venna
 
Database Management System 1
Database Management System 1Database Management System 1
Database Management System 1Swapnali Pawar
 
Entigrity constraint
Entigrity constraintEntigrity constraint
Entigrity constraintsuman kumar
 
SQL Tutorial for Beginners
SQL Tutorial for BeginnersSQL Tutorial for Beginners
SQL Tutorial for BeginnersAbdelhay Shafi
 
Introduction to structured query language
Introduction to structured query languageIntroduction to structured query language
Introduction to structured query languageHuda Alameen
 
Lecture 3 sql {basics ddl commands}
Lecture 3 sql {basics  ddl commands}Lecture 3 sql {basics  ddl commands}
Lecture 3 sql {basics ddl commands}Shubham Shukla
 
ALL ABOUT SQL AND RDBMS
ALL ABOUT SQL AND RDBMSALL ABOUT SQL AND RDBMS
ALL ABOUT SQL AND RDBMSgaurav koriya
 
Lecture 4 sql {basics keys and constraints}
Lecture 4 sql {basics  keys and constraints}Lecture 4 sql {basics  keys and constraints}
Lecture 4 sql {basics keys and constraints}Shubham Shukla
 
oracle Sql constraint
oracle  Sql constraint oracle  Sql constraint
oracle Sql constraint home
 

What's hot (19)

06.01 sql select distinct
06.01 sql select distinct06.01 sql select distinct
06.01 sql select distinct
 
Chapter 08
Chapter 08Chapter 08
Chapter 08
 
SQL
SQLSQL
SQL
 
Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)
 
Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
 
Obtain better data accuracy using reference tables
Obtain better data accuracy using reference tablesObtain better data accuracy using reference tables
Obtain better data accuracy using reference tables
 
Database Management System 1
Database Management System 1Database Management System 1
Database Management System 1
 
Db1 lecture4
Db1 lecture4Db1 lecture4
Db1 lecture4
 
Entigrity constraint
Entigrity constraintEntigrity constraint
Entigrity constraint
 
Sql
SqlSql
Sql
 
SQL Tutorial for Beginners
SQL Tutorial for BeginnersSQL Tutorial for Beginners
SQL Tutorial for Beginners
 
Introduction to structured query language
Introduction to structured query languageIntroduction to structured query language
Introduction to structured query language
 
Sql Tags
Sql TagsSql Tags
Sql Tags
 
Lecture 3 sql {basics ddl commands}
Lecture 3 sql {basics  ddl commands}Lecture 3 sql {basics  ddl commands}
Lecture 3 sql {basics ddl commands}
 
ALL ABOUT SQL AND RDBMS
ALL ABOUT SQL AND RDBMSALL ABOUT SQL AND RDBMS
ALL ABOUT SQL AND RDBMS
 
BIS05 Introduction to SQL
BIS05 Introduction to SQLBIS05 Introduction to SQL
BIS05 Introduction to SQL
 
Lecture 4 sql {basics keys and constraints}
Lecture 4 sql {basics  keys and constraints}Lecture 4 sql {basics  keys and constraints}
Lecture 4 sql {basics keys and constraints}
 
oracle Sql constraint
oracle  Sql constraint oracle  Sql constraint
oracle Sql constraint
 

Similar to Higher SQL (20)

SQL
SQLSQL
SQL
 
Sql
SqlSql
Sql
 
ADV Powepoint 4 Lec.pptx
ADV Powepoint 4 Lec.pptxADV Powepoint 4 Lec.pptx
ADV Powepoint 4 Lec.pptx
 
Chapter08
Chapter08Chapter08
Chapter08
 
SQL : introduction
SQL : introductionSQL : introduction
SQL : introduction
 
75864 sql
75864 sql75864 sql
75864 sql
 
Sql 2006
Sql 2006Sql 2006
Sql 2006
 
DEE 431 Introduction to MySql Slide 6
DEE 431 Introduction to MySql Slide 6DEE 431 Introduction to MySql Slide 6
DEE 431 Introduction to MySql Slide 6
 
Sql
SqlSql
Sql
 
SQL.pptx
SQL.pptxSQL.pptx
SQL.pptx
 
Sql functions
Sql functionsSql functions
Sql functions
 
Appendix A Tables
Appendix A   TablesAppendix A   Tables
Appendix A Tables
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
 
Dynamic websites lec2
Dynamic websites lec2Dynamic websites lec2
Dynamic websites lec2
 
Lab1 select statement
Lab1 select statementLab1 select statement
Lab1 select statement
 
Module03
Module03Module03
Module03
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
SQL Lesson 6 - Select.pdf
SQL Lesson 6 - Select.pdfSQL Lesson 6 - Select.pdf
SQL Lesson 6 - Select.pdf
 
Sql
SqlSql
Sql
 
Sql Basics | Edureka
Sql Basics | EdurekaSql Basics | Edureka
Sql Basics | Edureka
 

More from missstevenson01

Lesson 3 - Coding with Minecraft - Variables.pptx
Lesson 3 -  Coding with Minecraft -  Variables.pptxLesson 3 -  Coding with Minecraft -  Variables.pptx
Lesson 3 - Coding with Minecraft - Variables.pptxmissstevenson01
 
Lesson 2 - Coding with Minecraft - Events.pptx
Lesson 2 - Coding with Minecraft - Events.pptxLesson 2 - Coding with Minecraft - Events.pptx
Lesson 2 - Coding with Minecraft - Events.pptxmissstevenson01
 
Lesson 1 - Coding with Minecraft -Introduction.pptx
Lesson 1 - Coding with Minecraft -Introduction.pptxLesson 1 - Coding with Minecraft -Introduction.pptx
Lesson 1 - Coding with Minecraft -Introduction.pptxmissstevenson01
 
Lesson2 - Coding with Minecraft - Events.pptx
Lesson2 - Coding with Minecraft - Events.pptxLesson2 - Coding with Minecraft - Events.pptx
Lesson2 - Coding with Minecraft - Events.pptxmissstevenson01
 
Ethical hacking trojans, worms and spyware
Ethical hacking    trojans, worms and spywareEthical hacking    trojans, worms and spyware
Ethical hacking trojans, worms and spywaremissstevenson01
 
Ethical hacking anti virus
Ethical hacking   anti virusEthical hacking   anti virus
Ethical hacking anti virusmissstevenson01
 
Ethical hacking introduction to ethical hacking
Ethical hacking   introduction to ethical hackingEthical hacking   introduction to ethical hacking
Ethical hacking introduction to ethical hackingmissstevenson01
 
S1 internet safety-chattingonline
S1 internet safety-chattingonlineS1 internet safety-chattingonline
S1 internet safety-chattingonlinemissstevenson01
 
Video Games and Copyright laws
Video Games and Copyright lawsVideo Games and Copyright laws
Video Games and Copyright lawsmissstevenson01
 

More from missstevenson01 (20)

S3 environment
S3 environmentS3 environment
S3 environment
 
The Processor.pptx
The Processor.pptxThe Processor.pptx
The Processor.pptx
 
How Computers Work
How Computers WorkHow Computers Work
How Computers Work
 
Lesson 3 - Coding with Minecraft - Variables.pptx
Lesson 3 -  Coding with Minecraft -  Variables.pptxLesson 3 -  Coding with Minecraft -  Variables.pptx
Lesson 3 - Coding with Minecraft - Variables.pptx
 
Lesson 2 - Coding with Minecraft - Events.pptx
Lesson 2 - Coding with Minecraft - Events.pptxLesson 2 - Coding with Minecraft - Events.pptx
Lesson 2 - Coding with Minecraft - Events.pptx
 
Lesson 1 - Coding with Minecraft -Introduction.pptx
Lesson 1 - Coding with Minecraft -Introduction.pptxLesson 1 - Coding with Minecraft -Introduction.pptx
Lesson 1 - Coding with Minecraft -Introduction.pptx
 
Lesson2 - Coding with Minecraft - Events.pptx
Lesson2 - Coding with Minecraft - Events.pptxLesson2 - Coding with Minecraft - Events.pptx
Lesson2 - Coding with Minecraft - Events.pptx
 
Ethical hacking trojans, worms and spyware
Ethical hacking    trojans, worms and spywareEthical hacking    trojans, worms and spyware
Ethical hacking trojans, worms and spyware
 
Ethical hacking anti virus
Ethical hacking   anti virusEthical hacking   anti virus
Ethical hacking anti virus
 
Ethical hacking introduction to ethical hacking
Ethical hacking   introduction to ethical hackingEthical hacking   introduction to ethical hacking
Ethical hacking introduction to ethical hacking
 
S1 internet safety-chattingonline
S1 internet safety-chattingonlineS1 internet safety-chattingonline
S1 internet safety-chattingonline
 
S3 wireframe diagrams
S3 wireframe diagramsS3 wireframe diagrams
S3 wireframe diagrams
 
Sql
SqlSql
Sql
 
Alien database
Alien databaseAlien database
Alien database
 
Video Games and Copyright laws
Video Games and Copyright lawsVideo Games and Copyright laws
Video Games and Copyright laws
 
Games Design Document
Games Design DocumentGames Design Document
Games Design Document
 
Video game proposal
Video game proposalVideo game proposal
Video game proposal
 
Evaluation
EvaluationEvaluation
Evaluation
 
H evaluation
H evaluationH evaluation
H evaluation
 
H testing and debugging
H testing and debuggingH testing and debugging
H testing and debugging
 

Recently uploaded

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 

Recently uploaded (20)

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 

Higher SQL

  • 1.
  • 2. SQL SQL is a standard language for accessing databases. SQL stands for Structured Query Language. Using SQL you can execute queries against a database retrieve data from a database insert, update and delete records in a database SQL can create new databases and tables
  • 3. SQL SELECT SELECT Forename, Surname FROM Students;
  • 4. SQL SELECT SELECT Forename, Surname FROM Students;
  • 5. SQL SELECT SELECT Forename, Surname FROM Students WHERE TutorGroup = ‘2T1’;
  • 6. SQL SELECT SELECT Forename, Surname FROM Students WHERE TutorGroup = ‘2T1’;
  • 7. SQL SELECT – OR SELECT Forename, Surname FROM Students WHERE TutorGroup = ‘3R1’ OR TutorGroup = ‘3R2’;
  • 8. SQL SELECT – OR SELECT Forename, Surname FROM Students WHERE TutorGroup = ‘3R1’ OR TutorGroup = ‘3R2’;
  • 9. SQL SELECT – AND SELECT Forename, Surname FROM Students WHERE Forename = ‘Stephen’ AND TutorGroup = ‘3R1’;
  • 10. SQL SELECT – AND SELECT Forename, Surname FROM Students WHERE Forename = ‘Stephen’ AND TutorGroup = ‘3R1’;
  • 11. SQL SELECT * SELECT * FROM Students WHERE Surname = ‘French’;
  • 12. SQL SELECT * SELECT * FROM Students WHERE Surname = ‘French’;
  • 13. SQL SELECT – COMPARISONS Can use >, <, = comparison operators: SELECT * FROM Students WHERE Age >= 14 and Age <=17; Can also use BETWEEN: SELECT * FROM Students WHERE Surname BETWEEN ‘Langley’ AND ‘Jones’;
  • 14. SQL SELECT ORDER BY SELECT Forename, Surname FROM Students ORDER BY Surname;
  • 15. SQL SELECT ORDER BY SELECT Forename, Surname FROM Students ORDER BY Surname;
  • 16. SQL SELECT ORDER BY DESC SELECT Forename, Surname FROM Students ORDER BY Surname DESC;
  • 17. SQL SELECT ORDER BY DESC SELECT Forename, Surname FROM Students ORDER BY Surname DESC;
  • 18. SQL INSERT INTO INSERT INTO Students (CandidateNumber, Forename, Surname, DOB, TutorGroup) VALUES (07551881’, ‘Aisha’, ‘Obeke’, ‘08/03/01’, 2T2’);
  • 19. SQL INSERT INTO INSERT INTO Students (CandidateNumber, Forename, Surname, DOB, TutorGroup) VALUES (07551881’, ‘Aisha’, ‘Obeke’, ‘08/03/01’, 2T2’);
  • 20. SQL UPDATE UPDATE Students SET TutorGroup TO ‘2T2’ WHERE CandidateNumber = ‘07541120’;
  • 21. SQL UPDATE UPDATE Students SET TutorGroup TO ‘2T2’ WHERE CandidateNumber = ‘07541120’;
  • 22. SQL DELETE DELETE FROM Students WHERE CandidateNumber = ‘07743612’;
  • 23. SQL DELETE DELETE FROM Students WHERE CandidateNumber = ‘07743612’;
  • 24. Wildcards A wildcard character is used to replace one or more characters in a string. Wildcards are useful in situations when incomplete information is available. A LIKE operator is used with a wildcard. Two different wildcards that can be used: % (the percent symbol) is used to represent zero, one or multiple characters. _ (the underscore symbol) is used to represent a single character. (Access uses an astrisk (*) rather than a % and a question mark (?) rather than _)
  • 25. Wildcard examples Example Purpose WHERE surname LIKE ‘Thom%’ Used to find any values in the surname field that start with “Thom” WHERE surname LIKE ‘%son’ Used to find any values in the surname field that end with “son” WHERE surname LIKE ‘%is%’ Used to find any values that have “is” anywhere in the surname field. WHERE surname LIKE ‘_h%’ Used to find any values in the surname field that have “h” as the second character. WHERE surname LIKE ‘m % %’ Used to find any vlues in the surname field that start with “m” and have at least 3 characters. WHERE surname LIKE ‘a%Z’ Used to find any values in the surname field that start with “a” and end with “z”.
  • 26. Wildcard example Example 1 Used to search the database to display the name, swimming pool details, resort and resort type of any hotel in a coastal resort that starts with the letter ‘A’. SELECT hotelName, swimmingPool, resortName, resortType FROM Hotel, Resort WHERE Hotel.resortID = Resort.resortID AND resortName LIKE ‘A*’ AND resortType = ‘coastal’;
  • 27. Wildcard example Example 2 Used to display the customer’s full name, booking number, start date, hotel name and resort name of all customers who has an ‘h’ as the second letter of their surname. These details should be listed in alphabetical orger of surname: customers within the same surname should be listed so that the customer with the earliest holiday should be listed first. SELECT firstname, surname, bookingNo, hotelName, resortName, startDate FROM Customer, Booking, Hotel, Resort WHERE Customer.[customer#]=Booking.[customer#] AND Booking.hotelRef=Hotel.hotelRef AND Hotel.resortID=Resort.resortID AND surname LIKE ‘?h*’ ORDER BY surname ASC, startDate ASC;
  • 28. Wildcards SELECT Forename, Surname FROM Students WHERE TutorGroup LIKE= ‘3%’;
  • 29. Wildcards SELECT Forename, Surname FROM Students WHERE TutorGroup LIKE= ‘3%’;
  • 30. Wildcards SELECT Forename, Surname FROM Students WHERE TutorGroup LIKE= ‘%T%’;
  • 31. Wildcards SELECT Forename, Surname FROM Students WHERE TutorGroup LIKE= ‘%T%’;
  • 32. SQL INNER JOIN SELECT Orders.OrderID, Customers.CustomerName FROM Orders INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID Two tables, Orders and Customers Customer.CustomerID is PK in Customers table Orders.CustomerID is FK in Orders table
  • 33. SQL INNER JOIN SELECT Orders.OrderID, Customers.CustomerName FROM Orders INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID
  • 34. Aggregate Functions Aggregate functions operate on a set of rows to return a single, statistical value. You apply an aggregate to a set of rows, which may be: All the rows in a table Only those rows specified by a WHERE clause Those rows created by a GROUP BY clause (see later)
  • 35. Aggregate Functions Function Description AVG ( ) Returns the average value of a numeric column or expression COUNT ( ) Returns the number rows that match the criteria in the WHERE clause. MAX ( ) Returns the largest value of the selected column or expression MIN ( ) Returns the smallest value of the selected column or expression. SUM ( ) Returns the total sum of a numeric column or expressions. The most common aggregate functions used are listed below:
  • 36. Examples Uses readable headings to display the cheapest and dearest price per night. Used to display the average number of nights booked. SELECT MIN(pricePersonNight) AS [Cheapest Price per Night], MAX(pricePersonNight) AS [Dearest Price perNight] FROM Hotel; SELECT ROUND(AVG(numberNights),2) FROM Booking;
  • 37. Examples Used to display a list of the different types of resort together with the number of resorts in each of those categories. Uses a readable heading to display the total number of people booked into a hotel in July. SELECT resortType, COUNT (*) FROM Resort GROUP BY resortType; SELECT SUM(numberInParty) AS [People on holiday in July] FROM Booking WHERE startDate LIKE ‘*/07/*’;
  • 38. Arithmetic Expressions Arithmetic expressions can be used to compute values as part of a SELECT query. The arithmetic expressions can contain column names, numeric numbers and arithmetic operators. An Alias can be used to give any column in an answer table a temporary name.
  • 39. Examples The query below will display the name, price, quantity and cost of each product in a specified order. Executing the query produces the answer table below: SELECT productName AS ['Product Name'], price, quantity, price*quantity FROM Product, Order WHERE Product.productID = [Order].productID AND order# - 123456;
  • 40. We can make the table more readable by using an alias: Executing the query produces the answer table below: SELECT productName AS ['Product Name'], price, quantity, price*quantity AS ['Product Cost'] FROM Product, Order WHERE Product.productID = [Order].productID AND order# = 123456;
  • 41. Group by The GROUP BY clause is used in a SELECT to form sets (or goups) of records. It does this by gathering together all the records that have identical data in the specified column.
  • 42. Example The query below is used to display a list of products categories together with the dearest product in each of those categories. The category with the cheapest product is listed first.
  • 43. Example Use to display the number of bookings for hotels in coastal resorts. Show the resort type and use a readable heading for the results returned by the aggregate function.
  • 44. Example Use to display a list of each type of meal plan together with the number of bookings made for each of those meal plans. The details should be listed from the least popular meal plan to the most popular.