SlideShare a Scribd company logo
1 of 40
STRUCTURED
QUERY
LANGUAGE
SQL
Objectives
 Learn the basic COMMANDS and
FUNCTIONS of SQL
 Learn how to use SQL for data administration
(create tables, indexes and views)
 Learn how to use SQL for data manipulation
(add, modify, delete and retrieve data)
 Learn how to use SQL to query a database to
extract useful information
SQL functions
Data Manipulation Language (DML): It
includes commands to insert, update,
delete and retrieve data within the
database tables.
Data Definition Language (DDL): SQL
includes commands to create database
objects such as tables, indexes and
views, as well as commands to define
access right to those database objects.
Data Manipulation Language
 Set of syntax for querying, inserting and
updating of data in a database.
 DML includes the following commands:
 SELECT extracts data from a
database
 UPDATE updates data in a database
 DELETE deletes data from a database
 INSERT INTOinserts new data into a database
SELECT statement
 It is used to select data from a database.
 It must include the following:
 SELECT clause. Specifies the columns to
be displayed.
 FROM clause. Specifies the table
containing the columns
that are listed in the
SELECT clause.
SELECT statement
 Syntax:
SELECT column_name(s)
FROM table_name;
Asterisk (*) can be used to
select all the available
columns and records from a
table.
Examples:
 Retrieve all columns from EMPLOYEE
table
 Retrieve the Ssn (Social Security
Number),
Last name, First name and Middle Initial
from the table EMPLOYEE
SELECT DISTINCT
 The DISTINCT keyword can be used to return
only distinct (different) values.
 Syntax:
SELECT DISTINCT column_name(s)
FROM table_name;
Examples:
 Display the different department locations
 Display the different salary of employee
WHERE clause
 The WHERE clause is used to extract only
those records that fulfill a specified criterion.
 Syntax:
SELECT column_name(s)
FROM table_name
WHERE column_name operator value;
Examples:
 Display female employees only.
 Display all employees under Supervisor
333445555
Operators allowed in WHERE
clause
Operator Description
= Equal
<> Not Equal
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
BETWEEN & AND Between an inclusive range
LIKE Search for pattern
IN If you know to extract value you want
to return for at least one of the
columns
IS NULL Contain NULL value
IS NOT NULL Return columns with value
Examples:
 Display employees whose salary is
not equal to 25000
 Display employees whose salary is
greater than or equal to 38000
 Display employees whose salary is
greater than to 38000
 Display employees whose salary is
less than or equal to 25000
 Display employees whose salary is
less than to 25000
Examples:
 Display employees who's born in 1960's
 Display employees with a last name
alphabetically between "Jabbar" and "Smith“
 Display employees whose salary is
between 25000 and 40000
The IN operator allows you to specify multiple
values in a WHERE clause.
 Display the social security numbers of all
employees who work on project numbers 1, 2
or 3
Examples:
The LIKE condition use to perform wildcard
searches or patterns of valid search string values.
 % Denotes zero or many characters
 _ Denotes one character
 Display the SSN, first name, last name, salary and
department location id of employee whose last
name begins with letter ‘Z’
 Display the SSN, first name, last name, salary and
department location id of employee whose last
name have the letter o as the second character.
Examples:
The AND operator displays a record if both the
first condition and the second condition is true.
 Display the female dependent of Employee
number 333445555
The OR operator displays a record if either the
first condition or the second condition is true.
 Display the Essn of employee who works on
Project no 1 or 3
ORDER BY
 The ORDER BY keyword is used to sort the
result-set by a specified column.
 The ORDER BY keyword sort the records in
ascending order by default.
 Syntax:
SELECT column_name(s)
FROM table_name
ORDER BY column_name ASC/DESC;
Examples:
 Sort the Name of employees by Last name.
 Sort the Name of employees by Last name in
descending order
Using Sub query to Retrieve
Rows
 Syntax:
SELECT column_name(s) FROM table_name
WHERE column_name = (SELECT column_name
FROM table_name WHERE column_name
condition);
 SELECT Dep_id, Dependent_name, Sex, Bdate,
Relationship FROM company.dependent
WHERE Essn =(SELECT ssn FROM
company.employee WHERE Fname = 'Franklin'
and Lname = 'Wong');
FUNCTIONS
 MySQL supports built-in functions to speed up
the process of calculating data. Aggregate and
Scalar functions are commonly used in
performing calculations.
 Objectives:
 Evaluate the aggregate functions
 Evaluate the scalar functions
 Use the aggregate function in SELECT
statements
 Use the scalar functions in SELECT statements
What is Aggregate function
 Aggregate functions are commands that perform
arithmetic operation on the values in a table or all
records in the database such as computing average,
sum, getting the maximum, minimum and count that
meets specific criteria.
AGGREGATE FUNCTIONS DESCRIPTION
AVG() Returns the average value
COUNT() Returns the count of the number of rows returned
SUM() Returns the sum
MAX() Returns the maximum value
MIN() Returns the minimum value
How to use the Average
Function
 Syntax:
SELECT AVG(column_name)
FROM table_name;
 SELECT AVG(Salary) FROM
company.employee e;
 SELECT AVG(Salary) AS AverageofSalary
FROM company.employee e;
How to use the Count Function
 Syntax:
SELECT COUNT(column_name)
FROM table_name;
 SELECT COUNT(*) FROM
company.employee e;
How to use the Sum Function
 Syntax:
SELECT SUM(column_name)
FROM table_name;
 SELECT SUM(Hours) FROM
company.works_on w;
 SELECT SUM(Hours) FROM
company.works_on w WHERE Essn =
123456789;
How to use the Max Function
 Syntax:
SELECT MAX(column_name) FROM
table_name;
 SELECT MAX(Salary) FROM
company.employee e;
 SELECT MAX(Lname) FROM
company.employee e;
 SELECT MAX(Bdate) FROM
company.employee e;
How to use the Min Function
 Syntax:
SELECT MIN(column_name)
FROM table_name;
 SELECT MIN(Salary) FROM
company.employee e;
 SELECT MIN(Lname) FROM
company.employee e;
 SELECT MIN(Bdate) FROM
company.employee e;
What is Scalar Function
 Scalar functions operate and returns single
value based on the input value. MySQL
provides scalar functions that can be used to
manipulate dates and time types, strings and
numbers.
Scalar Function Description
UCASE() Converts field to upper case
LCASE() Converts field to lower case
MID() Return a substring starting from the specified position
ROUND() Rounds a numeric field to the number of decimal specified
NOW() Returns the current system date and time
FORMAT() Format how a field is to be displayed
How to use UCASE() Function
 Syntax:
SELECT UCASE(column_name)
FROM table_name;
 SELECT UCASE(Lname) FROM
company.employee;
How to use LCASE() Function
 Syntax:
SELECT LCASE(column_name)
FROM table_name;
 SELECT UCASE(Lname), LCASE(Fname)
FROM company.employee;
How to use MID() Function
 Syntax:
SELECT MID(column_name, start, length)
FROM table_name;
 Where:
 Start – specifies the starting position(starts at 1)
 Length – The number of characters to return.
 SELECT MID(Lname, 1, 3)
FROM company.employee e;
How to use ROUND() Function
 Syntax:
SELECT ROUND(column_name,decimals)
FROM table_name;
 SELECT ROUND(Salary,2)
FROM company.employee e;
How to use NOW() Function
 Syntax:
SELECT NOW();
GROUP BY STATEMENT
 Grouping result-set will help in identifying
clusters that will help in formulating tactical or
strategic decisions in an organization.
 Objectives
 Analyze the purpose of using group by statement
 Use group by statement to group result-set
 Evaluate the advantages of using group by
statement
How to use the GROUP BY
Statement
 Syntax:
SELECT column_name(s) FROM table_name
GROUP BY column_name;
 For each Department Location, retrieve the
department location, the number of employees in
the department location, and their average salary.
 For each project, retrieve the project number, the
project name, and the number of employees who
work on that project.
JOINS
 Objectives
 Analyze the process of joining two tables
 Distinguish left, right, inner and full join in
MySQL
 Evaluate the advantages of using JOIN in
SELECT statement
 Evaluate UNION and UNION ALL
 Use JOIN in SELECT statement
 JOINS are used to query data from two or
more tables by specifying relationship between
certain columns in these tables. Keys are used
to establish relationships between tables.
TYPES DESCRIPTION
INNER JOIN Return rows when there is at least one match in both tables
LEFT JOIN Return all rows from the left table, even if there are no matches in
the right table
RIGHT JOIN Return all rows from the right table, even if there are no matches
in the left table
FULL JOIN Return rows when there is a match in one of the tables
How to use the JOIN in SELECT
Statement
 Syntax:
SELECT column_name(s) FROM table_name1
JOIN table_name2 ON
table_name1.column_name = table_name2.column_name;
 SELECT e.Ssn, e.Lname, e.Fname, e.Minit,
dl.Dlocation FROM company.employee e
JOIN company.dept_locations dl ON e.DL_id =
dl.DL_id;
 INNER JOIN returns rows when there is at least one
match in both tables. If there are rows in table1 that
do not have matches in table2, those rows will NOT
be listed.
How to use LEFT JOIN
 Syntax:
SELECT column_name(s) FROM table_name1
LEFT JOIN table_name2 ON
table_name1.column_name
=table_name2.column_name;
 SELECT e.Ssn, e.Lname, e.Fname, e.Minit,
d.Dependent_name, d.Sex, d.Relationship
FROM company.employee e LEFT JOIN
company.dependent d ON e.ssn = d.essn
 LEFT JOIN returns all the rows from the left table
(employee), even if there are no matches in the
right table (dependent).
How to use RIGHT JOIN
 Syntax:
SELECT column_name(s) FROM table_name1
RIGHT JOIN table_name2 ON
table_name1.column_name =
table_name2.column_name;
 SELECT e.Ssn, e.Lname, e.Fname, e.Minit,
d.Dependent_name, d.Sex, d.Relationship
FROM company.employee e RIGHT JOIN
company.dependent d ON e.ssn = d.essn
 RIGHT JOIN returns all the rows from the right
table (dependent), even if there are no matches in
the left table (employee).
How to use UNION statement
 Syntax:
SELECT column_name(s) FROM
table_name1
UNION
SELECT column_name(s) FROM
table_name2
UNION command selects only distinct values
UNION ALL select all values
#Column names in first table must be equal to
column names in second table

More Related Content

Similar to Data Manipulation Language.pptx

SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functionsVikas Gupta
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive TechandMate
 
Its about a sql topic for basic structured query language
Its about a sql topic for basic structured query languageIts about a sql topic for basic structured query language
Its about a sql topic for basic structured query languageIMsKanchanaI
 
SQLSERVERQUERIES.pptx
SQLSERVERQUERIES.pptxSQLSERVERQUERIES.pptx
SQLSERVERQUERIES.pptxssuser6bf2d1
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxjainendraKUMAR55
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETEAbrar ali
 
ALL ABOUT SQL AND RDBMS
ALL ABOUT SQL AND RDBMSALL ABOUT SQL AND RDBMS
ALL ABOUT SQL AND RDBMSgaurav koriya
 
ADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsg
ADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsgADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsg
ADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsgzmulani8
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSabrinaShanta2
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSaiMiryala1
 
Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)Vidyasagar Mundroy
 

Similar to Data Manipulation Language.pptx (20)

SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
 
Its about a sql topic for basic structured query language
Its about a sql topic for basic structured query languageIts about a sql topic for basic structured query language
Its about a sql topic for basic structured query language
 
SQLSERVERQUERIES.pptx
SQLSERVERQUERIES.pptxSQLSERVERQUERIES.pptx
SQLSERVERQUERIES.pptx
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptx
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
 
ALL ABOUT SQL AND RDBMS
ALL ABOUT SQL AND RDBMSALL ABOUT SQL AND RDBMS
ALL ABOUT SQL AND RDBMS
 
sql language
sql languagesql language
sql language
 
Module03
Module03Module03
Module03
 
SQL
SQLSQL
SQL
 
Sql 2006
Sql 2006Sql 2006
Sql 2006
 
Sql slid
Sql slidSql slid
Sql slid
 
ADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsg
ADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsgADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsg
ADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsg
 
Sql
SqlSql
Sql
 
lect 2.pptx
lect 2.pptxlect 2.pptx
lect 2.pptx
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
 
SQL
SQLSQL
SQL
 
Db1 lecture4
Db1 lecture4Db1 lecture4
Db1 lecture4
 
Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)
 

More from EllenGracePorras

Lesson 3 Introduction to Human Computer Interaction.pptx
Lesson 3 Introduction to Human Computer Interaction.pptxLesson 3 Introduction to Human Computer Interaction.pptx
Lesson 3 Introduction to Human Computer Interaction.pptxEllenGracePorras
 
Lesson 4 Introduction to Human Computer Interaction.pptx
Lesson 4 Introduction to Human Computer Interaction.pptxLesson 4 Introduction to Human Computer Interaction.pptx
Lesson 4 Introduction to Human Computer Interaction.pptxEllenGracePorras
 
Geographic Information System(GIS).pptx
Geographic  Information System(GIS).pptxGeographic  Information System(GIS).pptx
Geographic Information System(GIS).pptxEllenGracePorras
 
Geographic Information Systems (GIS).pptx
Geographic  Information Systems (GIS).pptxGeographic  Information Systems (GIS).pptx
Geographic Information Systems (GIS).pptxEllenGracePorras
 
Advanced Database Systems.pptx
Advanced Database Systems.pptxAdvanced Database Systems.pptx
Advanced Database Systems.pptxEllenGracePorras
 
Advanced Database Systems - Presentation 4.pptx
Advanced Database Systems - Presentation 4.pptxAdvanced Database Systems - Presentation 4.pptx
Advanced Database Systems - Presentation 4.pptxEllenGracePorras
 
Advanced Database Systems - Presentation 3.pptx
Advanced Database Systems - Presentation 3.pptxAdvanced Database Systems - Presentation 3.pptx
Advanced Database Systems - Presentation 3.pptxEllenGracePorras
 
Advanced Database Systems - Presentation 2.pptx
Advanced Database Systems - Presentation 2.pptxAdvanced Database Systems - Presentation 2.pptx
Advanced Database Systems - Presentation 2.pptxEllenGracePorras
 
Advanced Database Systems - Presentation 1 with quiz.pptx
Advanced Database Systems - Presentation 1 with quiz.pptxAdvanced Database Systems - Presentation 1 with quiz.pptx
Advanced Database Systems - Presentation 1 with quiz.pptxEllenGracePorras
 
Structured Query Language (SQL) Part 2.pptx
Structured Query Language (SQL) Part 2.pptxStructured Query Language (SQL) Part 2.pptx
Structured Query Language (SQL) Part 2.pptxEllenGracePorras
 
.Net Technologies Lesson 1.pptx
.Net Technologies Lesson 1.pptx.Net Technologies Lesson 1.pptx
.Net Technologies Lesson 1.pptxEllenGracePorras
 
Structured Query Language (SQL).pptx
Structured Query Language (SQL).pptxStructured Query Language (SQL).pptx
Structured Query Language (SQL).pptxEllenGracePorras
 

More from EllenGracePorras (18)

Lesson 3 Introduction to Human Computer Interaction.pptx
Lesson 3 Introduction to Human Computer Interaction.pptxLesson 3 Introduction to Human Computer Interaction.pptx
Lesson 3 Introduction to Human Computer Interaction.pptx
 
Lesson 4 Introduction to Human Computer Interaction.pptx
Lesson 4 Introduction to Human Computer Interaction.pptxLesson 4 Introduction to Human Computer Interaction.pptx
Lesson 4 Introduction to Human Computer Interaction.pptx
 
Geographic Information System(GIS).pptx
Geographic  Information System(GIS).pptxGeographic  Information System(GIS).pptx
Geographic Information System(GIS).pptx
 
Geographic Information Systems (GIS).pptx
Geographic  Information Systems (GIS).pptxGeographic  Information Systems (GIS).pptx
Geographic Information Systems (GIS).pptx
 
Advanced Database Systems.pptx
Advanced Database Systems.pptxAdvanced Database Systems.pptx
Advanced Database Systems.pptx
 
Advanced Database Systems - Presentation 4.pptx
Advanced Database Systems - Presentation 4.pptxAdvanced Database Systems - Presentation 4.pptx
Advanced Database Systems - Presentation 4.pptx
 
Advanced Database Systems - Presentation 3.pptx
Advanced Database Systems - Presentation 3.pptxAdvanced Database Systems - Presentation 3.pptx
Advanced Database Systems - Presentation 3.pptx
 
Advanced Database Systems - Presentation 2.pptx
Advanced Database Systems - Presentation 2.pptxAdvanced Database Systems - Presentation 2.pptx
Advanced Database Systems - Presentation 2.pptx
 
Advanced Database Systems - Presentation 1 with quiz.pptx
Advanced Database Systems - Presentation 1 with quiz.pptxAdvanced Database Systems - Presentation 1 with quiz.pptx
Advanced Database Systems - Presentation 1 with quiz.pptx
 
Structured Query Language (SQL) Part 2.pptx
Structured Query Language (SQL) Part 2.pptxStructured Query Language (SQL) Part 2.pptx
Structured Query Language (SQL) Part 2.pptx
 
SQL Where Clause.pptx
SQL Where Clause.pptxSQL Where Clause.pptx
SQL Where Clause.pptx
 
SQL Statements.pptx
SQL Statements.pptxSQL Statements.pptx
SQL Statements.pptx
 
Information Management
Information ManagementInformation Management
Information Management
 
Lesson 2 HCI 2.pptx
Lesson 2 HCI 2.pptxLesson 2 HCI 2.pptx
Lesson 2 HCI 2.pptx
 
Lesson 2 HCI 2.pdf
Lesson 2 HCI 2.pdfLesson 2 HCI 2.pdf
Lesson 2 HCI 2.pdf
 
.Net Technologies Lesson 1.pptx
.Net Technologies Lesson 1.pptx.Net Technologies Lesson 1.pptx
.Net Technologies Lesson 1.pptx
 
CC 1/L Introduction.pptx
CC 1/L Introduction.pptxCC 1/L Introduction.pptx
CC 1/L Introduction.pptx
 
Structured Query Language (SQL).pptx
Structured Query Language (SQL).pptxStructured Query Language (SQL).pptx
Structured Query Language (SQL).pptx
 

Recently uploaded

Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
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
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
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
 
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
 
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
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
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
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 

Recently uploaded (20)

Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
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
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
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...
 
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?
 
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
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
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
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 

Data Manipulation Language.pptx

  • 2. Objectives  Learn the basic COMMANDS and FUNCTIONS of SQL  Learn how to use SQL for data administration (create tables, indexes and views)  Learn how to use SQL for data manipulation (add, modify, delete and retrieve data)  Learn how to use SQL to query a database to extract useful information
  • 3. SQL functions Data Manipulation Language (DML): It includes commands to insert, update, delete and retrieve data within the database tables. Data Definition Language (DDL): SQL includes commands to create database objects such as tables, indexes and views, as well as commands to define access right to those database objects.
  • 4. Data Manipulation Language  Set of syntax for querying, inserting and updating of data in a database.  DML includes the following commands:  SELECT extracts data from a database  UPDATE updates data in a database  DELETE deletes data from a database  INSERT INTOinserts new data into a database
  • 5. SELECT statement  It is used to select data from a database.  It must include the following:  SELECT clause. Specifies the columns to be displayed.  FROM clause. Specifies the table containing the columns that are listed in the SELECT clause.
  • 6. SELECT statement  Syntax: SELECT column_name(s) FROM table_name; Asterisk (*) can be used to select all the available columns and records from a table.
  • 7. Examples:  Retrieve all columns from EMPLOYEE table  Retrieve the Ssn (Social Security Number), Last name, First name and Middle Initial from the table EMPLOYEE
  • 8. SELECT DISTINCT  The DISTINCT keyword can be used to return only distinct (different) values.  Syntax: SELECT DISTINCT column_name(s) FROM table_name;
  • 9. Examples:  Display the different department locations  Display the different salary of employee
  • 10. WHERE clause  The WHERE clause is used to extract only those records that fulfill a specified criterion.  Syntax: SELECT column_name(s) FROM table_name WHERE column_name operator value;
  • 11. Examples:  Display female employees only.  Display all employees under Supervisor 333445555
  • 12. Operators allowed in WHERE clause Operator Description = Equal <> Not Equal > Greater than < Less than >= Greater than or equal <= Less than or equal BETWEEN & AND Between an inclusive range LIKE Search for pattern IN If you know to extract value you want to return for at least one of the columns IS NULL Contain NULL value IS NOT NULL Return columns with value
  • 13. Examples:  Display employees whose salary is not equal to 25000  Display employees whose salary is greater than or equal to 38000  Display employees whose salary is greater than to 38000  Display employees whose salary is less than or equal to 25000  Display employees whose salary is less than to 25000
  • 14. Examples:  Display employees who's born in 1960's  Display employees with a last name alphabetically between "Jabbar" and "Smith“  Display employees whose salary is between 25000 and 40000 The IN operator allows you to specify multiple values in a WHERE clause.  Display the social security numbers of all employees who work on project numbers 1, 2 or 3
  • 15. Examples: The LIKE condition use to perform wildcard searches or patterns of valid search string values.  % Denotes zero or many characters  _ Denotes one character  Display the SSN, first name, last name, salary and department location id of employee whose last name begins with letter ‘Z’  Display the SSN, first name, last name, salary and department location id of employee whose last name have the letter o as the second character.
  • 16. Examples: The AND operator displays a record if both the first condition and the second condition is true.  Display the female dependent of Employee number 333445555 The OR operator displays a record if either the first condition or the second condition is true.  Display the Essn of employee who works on Project no 1 or 3
  • 17. ORDER BY  The ORDER BY keyword is used to sort the result-set by a specified column.  The ORDER BY keyword sort the records in ascending order by default.  Syntax: SELECT column_name(s) FROM table_name ORDER BY column_name ASC/DESC;
  • 18. Examples:  Sort the Name of employees by Last name.  Sort the Name of employees by Last name in descending order
  • 19. Using Sub query to Retrieve Rows  Syntax: SELECT column_name(s) FROM table_name WHERE column_name = (SELECT column_name FROM table_name WHERE column_name condition);  SELECT Dep_id, Dependent_name, Sex, Bdate, Relationship FROM company.dependent WHERE Essn =(SELECT ssn FROM company.employee WHERE Fname = 'Franklin' and Lname = 'Wong');
  • 20. FUNCTIONS  MySQL supports built-in functions to speed up the process of calculating data. Aggregate and Scalar functions are commonly used in performing calculations.  Objectives:  Evaluate the aggregate functions  Evaluate the scalar functions  Use the aggregate function in SELECT statements  Use the scalar functions in SELECT statements
  • 21. What is Aggregate function  Aggregate functions are commands that perform arithmetic operation on the values in a table or all records in the database such as computing average, sum, getting the maximum, minimum and count that meets specific criteria. AGGREGATE FUNCTIONS DESCRIPTION AVG() Returns the average value COUNT() Returns the count of the number of rows returned SUM() Returns the sum MAX() Returns the maximum value MIN() Returns the minimum value
  • 22. How to use the Average Function  Syntax: SELECT AVG(column_name) FROM table_name;  SELECT AVG(Salary) FROM company.employee e;  SELECT AVG(Salary) AS AverageofSalary FROM company.employee e;
  • 23. How to use the Count Function  Syntax: SELECT COUNT(column_name) FROM table_name;  SELECT COUNT(*) FROM company.employee e;
  • 24. How to use the Sum Function  Syntax: SELECT SUM(column_name) FROM table_name;  SELECT SUM(Hours) FROM company.works_on w;  SELECT SUM(Hours) FROM company.works_on w WHERE Essn = 123456789;
  • 25. How to use the Max Function  Syntax: SELECT MAX(column_name) FROM table_name;  SELECT MAX(Salary) FROM company.employee e;  SELECT MAX(Lname) FROM company.employee e;  SELECT MAX(Bdate) FROM company.employee e;
  • 26. How to use the Min Function  Syntax: SELECT MIN(column_name) FROM table_name;  SELECT MIN(Salary) FROM company.employee e;  SELECT MIN(Lname) FROM company.employee e;  SELECT MIN(Bdate) FROM company.employee e;
  • 27. What is Scalar Function  Scalar functions operate and returns single value based on the input value. MySQL provides scalar functions that can be used to manipulate dates and time types, strings and numbers. Scalar Function Description UCASE() Converts field to upper case LCASE() Converts field to lower case MID() Return a substring starting from the specified position ROUND() Rounds a numeric field to the number of decimal specified NOW() Returns the current system date and time FORMAT() Format how a field is to be displayed
  • 28. How to use UCASE() Function  Syntax: SELECT UCASE(column_name) FROM table_name;  SELECT UCASE(Lname) FROM company.employee;
  • 29. How to use LCASE() Function  Syntax: SELECT LCASE(column_name) FROM table_name;  SELECT UCASE(Lname), LCASE(Fname) FROM company.employee;
  • 30. How to use MID() Function  Syntax: SELECT MID(column_name, start, length) FROM table_name;  Where:  Start – specifies the starting position(starts at 1)  Length – The number of characters to return.  SELECT MID(Lname, 1, 3) FROM company.employee e;
  • 31. How to use ROUND() Function  Syntax: SELECT ROUND(column_name,decimals) FROM table_name;  SELECT ROUND(Salary,2) FROM company.employee e;
  • 32. How to use NOW() Function  Syntax: SELECT NOW();
  • 33. GROUP BY STATEMENT  Grouping result-set will help in identifying clusters that will help in formulating tactical or strategic decisions in an organization.  Objectives  Analyze the purpose of using group by statement  Use group by statement to group result-set  Evaluate the advantages of using group by statement
  • 34. How to use the GROUP BY Statement  Syntax: SELECT column_name(s) FROM table_name GROUP BY column_name;  For each Department Location, retrieve the department location, the number of employees in the department location, and their average salary.  For each project, retrieve the project number, the project name, and the number of employees who work on that project.
  • 35. JOINS  Objectives  Analyze the process of joining two tables  Distinguish left, right, inner and full join in MySQL  Evaluate the advantages of using JOIN in SELECT statement  Evaluate UNION and UNION ALL  Use JOIN in SELECT statement
  • 36.  JOINS are used to query data from two or more tables by specifying relationship between certain columns in these tables. Keys are used to establish relationships between tables. TYPES DESCRIPTION INNER JOIN Return rows when there is at least one match in both tables LEFT JOIN Return all rows from the left table, even if there are no matches in the right table RIGHT JOIN Return all rows from the right table, even if there are no matches in the left table FULL JOIN Return rows when there is a match in one of the tables
  • 37. How to use the JOIN in SELECT Statement  Syntax: SELECT column_name(s) FROM table_name1 JOIN table_name2 ON table_name1.column_name = table_name2.column_name;  SELECT e.Ssn, e.Lname, e.Fname, e.Minit, dl.Dlocation FROM company.employee e JOIN company.dept_locations dl ON e.DL_id = dl.DL_id;  INNER JOIN returns rows when there is at least one match in both tables. If there are rows in table1 that do not have matches in table2, those rows will NOT be listed.
  • 38. How to use LEFT JOIN  Syntax: SELECT column_name(s) FROM table_name1 LEFT JOIN table_name2 ON table_name1.column_name =table_name2.column_name;  SELECT e.Ssn, e.Lname, e.Fname, e.Minit, d.Dependent_name, d.Sex, d.Relationship FROM company.employee e LEFT JOIN company.dependent d ON e.ssn = d.essn  LEFT JOIN returns all the rows from the left table (employee), even if there are no matches in the right table (dependent).
  • 39. How to use RIGHT JOIN  Syntax: SELECT column_name(s) FROM table_name1 RIGHT JOIN table_name2 ON table_name1.column_name = table_name2.column_name;  SELECT e.Ssn, e.Lname, e.Fname, e.Minit, d.Dependent_name, d.Sex, d.Relationship FROM company.employee e RIGHT JOIN company.dependent d ON e.ssn = d.essn  RIGHT JOIN returns all the rows from the right table (dependent), even if there are no matches in the left table (employee).
  • 40. How to use UNION statement  Syntax: SELECT column_name(s) FROM table_name1 UNION SELECT column_name(s) FROM table_name2 UNION command selects only distinct values UNION ALL select all values #Column names in first table must be equal to column names in second table