SlideShare a Scribd company logo
SQL
Structured Query Language
PRIYABRAT KAR
• SQL is a standard language for accessing
databases.
• SELECT * FROM Customers;
 What is SQL?
• SQL stands for Structured Query Language.
• SQL lets you access and manipulate
databases
• SQL is an ANSI (American National
Standards Institute) standard
 What Can SQL do?
• SQL can execute queries against a database
• SQL can retrieve data from a database
• SQL can insert records in a database
• SQL can update records in a database
• SQL can delete records from a database
• SQL can create new databases
• SQL can create new tables in a database
• SQL can create stored procedures in a database
• SQL can create views in a database
• SQL can set permissions on tables, procedures,
and views
 Semicolon after SQL Statements?
• Some database systems require a semicolon at the end
of each SQL statement.
• Semicolon is the standard way to separate each SQL
statement in database systems that allow more than one SQL
statement to be executed in the same call to the server.
• In this tutorial, we will use semicolon at the end of each
SQL statement.
 Some of The Most Important SQL Commands
• SELECT - extracts data from a database
• UPDATE - updates data in a database
• DELETE - deletes data from a database
• INSERT INTO - inserts new data into a
database
• CREATE DATABASE - creates a new
database
• ALTER DATABASE - modifies a database
• CREATE TABLE - creates a new table
• ALTER TABLE - modifies a table
• DROP TABLE - deletes a table
• CREATE INDEX - creates an index (search
key)
• DROP INDEX - deletes an index
 The SQL SELECT Statement
The SELECT statement is used to select data from a
database.
• The result is stored in a result table, called the result-
set.
• SQL SELECT Syntax
SELECT column_name,column_name
FROM table_name;
and
SELECT * FROM table_name;
 The SQL WHERE Clause
• The WHERE clause is used to extract only those records
that fulfill a specified criterion.
• SQL WHERE Syntax
SELECT column_name,column_name
FROM table_name
WHERE column_name operator value;
• The AND & OR operators are used to filter
records based on more than one condition.
 The SQL ORDER BY Keyword
• The ORDER BY keyword is used to sort the result-set by
one or more columns.
• The ORDER BY keyword sorts the records in ascending
order by default. To sort the records in a descending
order, you can use the DESC keyword.
• SQL ORDER BY Syntax
SELECT column_name, column_name
FROM table_name
ORDER BY column_name ASC|DESC, column_name
ASC|DESC;
 The SQL UPDATE Statement
• The UPDATE statement is used to update existing
records in a table.
• SQL UPDATE Syntax
UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;
 The SQL DELETE Statement
• The DELETE statement is used to delete rows in a
table.
• SQL DELETE Syntax
DELETE FROM table_name
WHERE some_column=some_value;
 The SQL LIKE Operator
• The LIKE operator is used to search for a specified
pattern in a column.
• SQL LIKE Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name LIKE pattern;
 SQL Wildcard Characters
In SQL, wildcard characters are used with the SQL LIKE operator.
• SQL wildcards are used to search for data within a table.
With SQL, the wildcards are:
Wildcard Description
% A substitute for zero or more characters
_ A substitute for a single character
[charlist] Sets and ranges of characters to match
[!charlist] Matches only a character NOT specified within the
brackets
 SQL Joins
• SQL joins are used to combine rows from two or more
tables.
 Different SQL JOINs
• Before we continue with examples, we will list the types the
different SQL JOINs you can use:
• INNER JOIN: Returns all rows when there is at least one
match in BOTH tables
• LEFT JOIN: Return all rows from the left table, and the
matched rows from the right table
• RIGHT JOIN: Return all rows from the right table, and the
matched rows from the left table
• FULL JOIN: Return all rows when there is a match in ONE
of the tables
 SQL INNER JOIN Keyword
• The INNER JOIN keyword selects all rows from
both tables as long as there is a match between the
columns in both tables.
• SQL INNER JOIN Syntax
SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name=table2.column_name;
or:
• SELECT column_name(s)
FROM table1
JOIN table2
ON table1.column_name=table2.column_name;
PS! INNER JOIN is the same as JOIN.
Sql Tutorials
 SQL LEFT JOIN Keyword
• The LEFT JOIN keyword returns all rows from the left table
(table1), with the matching rows in the right table (table2).
The result is NULL in the right side when there is no match.
• SQL LEFT JOIN Syntax
SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name=table2.column_name;
or:
• SELECT column_name(s)
FROM table1
LEFT OUTER JOIN table2
ON table1.column_name=table2.column_name;
Sql Tutorials
 SQL RIGHT JOIN Keyword
• The RIGHT JOIN keyword returns all rows from the right
table (table2), with the matching rows in the left table
(table1). The result is NULL in the left side when there is
no match.
• SQL RIGHT JOIN Syntax
SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name=table2.column_name;
or:
• SELECT column_name(s)
FROM table1
RIGHT OUTER JOIN table2
ON table1.column_name=table2.column_name;
Sql Tutorials
 SQL FULL OUTER JOIN Keyword
• The FULL OUTER JOIN keyword returns all rows
from the left table (table1) and from the right table
(table2).
• The FULL OUTER JOIN keyword combines the
result of both LEFT and RIGHT joins.
• SQL FULL OUTER JOIN Syntax
SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name=table2.column_name;
Sql Tutorials
 The SQL CREATE TABLE Statement
• The CREATE TABLE statement is used to create a
table in a database.
• Tables are organized into rows and columns; and each
table must have a name.
• SQL CREATE TABLE Syntax
CREATE TABLE table_name
(
column_name1 data_type(size),
column_name2 data_type(size),
column_name3 data_type(size),
....
);
 SQL Constraints
SQL constraints are used to specify rules for the data in a table.
• If there is any violation between the constraint and the data
action, the action is aborted by the constraint.
• Constraints can be specified when the table is created (inside the
CREATE TABLE statement) or after the table is created (inside
the ALTER TABLE statement).
• SQL CREATE TABLE + CONSTRAINT Syntax
CREATE TABLE table_name
(
column_name1 data_type(size) constraint_name,
column_name2 data_type(size) constraint_name,
column_name3 data_type(size) constraint_name,
....
);
 In SQL, we have the following constraints:
• NOT NULL - Indicates that a column cannot store NULL
value
• UNIQUE - Ensures that each row for a column must have
a unique value
• PRIMARY KEY - A combination of a NOT NULL and
UNIQUE. Ensures that a column (or combination of two
or more columns) have an unique identity which helps to
find a particular record in a table more easily and quickly
• FOREIGN KEY - Ensure the referential integrity of the
data in one table to match values in another table
• CHECK - Ensures that the value in a column meets a
specific condition
• DEFAULT - Specifies a default value when specified
none for this column
 SQL Aggregate Functions
• SQL aggregate functions return a single
value, calculated from values in a column.
• Useful aggregate functions:
AVG() - Returns the average value
COUNT() - Returns the number of rows
FIRST() - Returns the first value
LAST() - Returns the last value
MAX() - Returns the largest value
MIN() - Returns the smallest value
SUM() - Returns the sum
 SQL Scalar functions
• SQL scalar functions return a single value, based on
the input value.
• Useful scalar functions:
UCASE() - Converts a field to upper case
LCASE() - Converts a field to lower case
MID() - Extract characters from a text field
LEN() - Returns the length of a text field
ROUND() - Rounds a numeric field to the number of
decimals specified
NOW() - Returns the current system date and time
FORMAT() - Formats how a field is to be displayed
Thank You

More Related Content

DOCX
Learning sql from w3schools
farhan516
 
PPT
Mysql
TSUBHASHRI
 
PPTX
SQL for interview
Aditya Kumar Tripathy
 
DOC
SQL
Shunya Ram
 
PPT
SQL select statement and functions
Vikas Gupta
 
PPTX
Sql and Sql commands
Knowledge Center Computer
 
PPTX
Sql(structured query language)
Ishucs
 
Learning sql from w3schools
farhan516
 
Mysql
TSUBHASHRI
 
SQL for interview
Aditya Kumar Tripathy
 
SQL select statement and functions
Vikas Gupta
 
Sql and Sql commands
Knowledge Center Computer
 
Sql(structured query language)
Ishucs
 

What's hot (20)

PDF
SQL Overview
Stewart Rogers
 
PPTX
introdution to SQL and SQL functions
farwa waqar
 
PPT
Introduction to structured query language (sql)
Sabana Maharjan
 
PPTX
SQL
Vineeta Garg
 
PPTX
SQL
Shyam Khant
 
PPTX
Aggregate function
Rayhan Chowdhury
 
PPT
Introduction to-sql
BG Java EE Course
 
PPTX
Sql queries presentation
NITISH KUMAR
 
PPT
Introduction to sql
VARSHAKUMARI49
 
PPTX
Sql commands
Pooja Dixit
 
PPT
SQL Queries
Nilt1234
 
PPTX
Oraclesql
Priya Goyal
 
PPTX
Sql subquery
Raveena Thakur
 
PPT
SQL select clause
arpit bhadoriya
 
PPT
Sql dml & tcl 2
Dr. C.V. Suresh Babu
 
PPTX
SQL Basics
Hammad Rasheed
 
PPTX
Structured query language(sql)ppt
Gowarthini
 
PDF
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
Prashant Kumar
 
PDF
FP304 DATABASE SYSTEM PAPER FINAL EXAM AGAIN
Syahriha Ruslan
 
SQL Overview
Stewart Rogers
 
introdution to SQL and SQL functions
farwa waqar
 
Introduction to structured query language (sql)
Sabana Maharjan
 
Aggregate function
Rayhan Chowdhury
 
Introduction to-sql
BG Java EE Course
 
Sql queries presentation
NITISH KUMAR
 
Introduction to sql
VARSHAKUMARI49
 
Sql commands
Pooja Dixit
 
SQL Queries
Nilt1234
 
Oraclesql
Priya Goyal
 
Sql subquery
Raveena Thakur
 
SQL select clause
arpit bhadoriya
 
Sql dml & tcl 2
Dr. C.V. Suresh Babu
 
SQL Basics
Hammad Rasheed
 
Structured query language(sql)ppt
Gowarthini
 
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
Prashant Kumar
 
FP304 DATABASE SYSTEM PAPER FINAL EXAM AGAIN
Syahriha Ruslan
 
Ad

Similar to Sql Tutorials (20)

PPTX
Sql slid
pacatarpit
 
PPT
MY SQL
sundar
 
PPT
Mysql 120831075600-phpapp01
sagaroceanic11
 
PPTX
Structure Query Language Advance Training
parisaxena1418
 
PDF
SQL -Beginner To Intermediate Level.pdf
DraguClaudiu
 
PDF
Structure query language, database course
yunussufyan2024
 
PPTX
SQL Query
Imam340267
 
PPT
INTRODUCTION TO SQL QUERIES REALTED BRIEF
VADAPALLYPRAVEENKUMA1
 
DOCX
SQL report
Ahmad Zahid
 
PPTX
Avinash database
avibmas
 
PPTX
2..basic queries.pptx
MalaikaRahatQurashi
 
PPTX
Database Overview
Livares Technologies Pvt Ltd
 
PDF
Sql basics v2
Yousuf Akhtar Sultan
 
PPTX
SQL : Structured Query Language
Abhishek Gautam
 
PPTX
SQL
Jerin John
 
PPTX
SQL
Jerin John
 
PPTX
Sql practise for beginners
ISsoft
 
PPTX
Sql
Aman Lalpuria
 
PPTX
Sql basics
Genesis Omo
 
PDF
SQL for data scientist And data analysist Advanced
swethasetty5
 
Sql slid
pacatarpit
 
MY SQL
sundar
 
Mysql 120831075600-phpapp01
sagaroceanic11
 
Structure Query Language Advance Training
parisaxena1418
 
SQL -Beginner To Intermediate Level.pdf
DraguClaudiu
 
Structure query language, database course
yunussufyan2024
 
SQL Query
Imam340267
 
INTRODUCTION TO SQL QUERIES REALTED BRIEF
VADAPALLYPRAVEENKUMA1
 
SQL report
Ahmad Zahid
 
Avinash database
avibmas
 
2..basic queries.pptx
MalaikaRahatQurashi
 
Database Overview
Livares Technologies Pvt Ltd
 
Sql basics v2
Yousuf Akhtar Sultan
 
SQL : Structured Query Language
Abhishek Gautam
 
Sql practise for beginners
ISsoft
 
Sql basics
Genesis Omo
 
SQL for data scientist And data analysist Advanced
swethasetty5
 
Ad

Recently uploaded (20)

PDF
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
Hyogeun Oh
 
PDF
Principles of Food Science and Nutritions
Dr. Yogesh Kumar Kosariya
 
PPTX
Chapter_Seven_Construction_Reliability_Elective_III_Msc CM
SubashKumarBhattarai
 
PPTX
easa module 3 funtamental electronics.pptx
tryanothert7
 
PDF
A Framework for Securing Personal Data Shared by Users on the Digital Platforms
ijcncjournal019
 
PPTX
Production of bioplastic from fruit peels.pptx
alwingeorgealwingeor
 
PPTX
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
Dr. Rahul Kumar
 
PPTX
Module_II_Data_Science_Project_Management.pptx
anshitanarain
 
PDF
Introduction to Data Science: data science process
ShivarkarSandip
 
PDF
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
PDF
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
PPTX
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
ghousebhasha2007
 
PPTX
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
VinayB68
 
PDF
Cryptography and Information :Security Fundamentals
Dr. Madhuri Jawale
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PPTX
Civil Engineering Practices_BY Sh.JP Mishra 23.09.pptx
bineetmishra1990
 
PPTX
Simulation of electric circuit laws using tinkercad.pptx
VidhyaH3
 
PDF
Activated Carbon for Water and Wastewater Treatment_ Integration of Adsorptio...
EmilianoRodriguezTll
 
PDF
July 2025: Top 10 Read Articles Advanced Information Technology
ijait
 
PPTX
EE3303-EM-I 25.7.25 electrical machines.pptx
Nagen87
 
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
Hyogeun Oh
 
Principles of Food Science and Nutritions
Dr. Yogesh Kumar Kosariya
 
Chapter_Seven_Construction_Reliability_Elective_III_Msc CM
SubashKumarBhattarai
 
easa module 3 funtamental electronics.pptx
tryanothert7
 
A Framework for Securing Personal Data Shared by Users on the Digital Platforms
ijcncjournal019
 
Production of bioplastic from fruit peels.pptx
alwingeorgealwingeor
 
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
Dr. Rahul Kumar
 
Module_II_Data_Science_Project_Management.pptx
anshitanarain
 
Introduction to Data Science: data science process
ShivarkarSandip
 
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
ghousebhasha2007
 
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
VinayB68
 
Cryptography and Information :Security Fundamentals
Dr. Madhuri Jawale
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
Civil Engineering Practices_BY Sh.JP Mishra 23.09.pptx
bineetmishra1990
 
Simulation of electric circuit laws using tinkercad.pptx
VidhyaH3
 
Activated Carbon for Water and Wastewater Treatment_ Integration of Adsorptio...
EmilianoRodriguezTll
 
July 2025: Top 10 Read Articles Advanced Information Technology
ijait
 
EE3303-EM-I 25.7.25 electrical machines.pptx
Nagen87
 

Sql Tutorials

  • 2. • SQL is a standard language for accessing databases. • SELECT * FROM Customers;
  • 3.  What is SQL? • SQL stands for Structured Query Language. • SQL lets you access and manipulate databases • SQL is an ANSI (American National Standards Institute) standard
  • 4.  What Can SQL do? • SQL can execute queries against a database • SQL can retrieve data from a database • SQL can insert records in a database • SQL can update records in a database • SQL can delete records from a database • SQL can create new databases • SQL can create new tables in a database • SQL can create stored procedures in a database • SQL can create views in a database • SQL can set permissions on tables, procedures, and views
  • 5.  Semicolon after SQL Statements? • Some database systems require a semicolon at the end of each SQL statement. • Semicolon is the standard way to separate each SQL statement in database systems that allow more than one SQL statement to be executed in the same call to the server. • In this tutorial, we will use semicolon at the end of each SQL statement.
  • 6.  Some of The Most Important SQL Commands • SELECT - extracts data from a database • UPDATE - updates data in a database • DELETE - deletes data from a database • INSERT INTO - inserts new data into a database • CREATE DATABASE - creates a new database • ALTER DATABASE - modifies a database • CREATE TABLE - creates a new table • ALTER TABLE - modifies a table • DROP TABLE - deletes a table • CREATE INDEX - creates an index (search key) • DROP INDEX - deletes an index
  • 7.  The SQL SELECT Statement The SELECT statement is used to select data from a database. • The result is stored in a result table, called the result- set. • SQL SELECT Syntax SELECT column_name,column_name FROM table_name; and SELECT * FROM table_name;
  • 8.  The SQL WHERE Clause • The WHERE clause is used to extract only those records that fulfill a specified criterion. • SQL WHERE Syntax SELECT column_name,column_name FROM table_name WHERE column_name operator value; • The AND & OR operators are used to filter records based on more than one condition.
  • 9.  The SQL ORDER BY Keyword • The ORDER BY keyword is used to sort the result-set by one or more columns. • The ORDER BY keyword sorts the records in ascending order by default. To sort the records in a descending order, you can use the DESC keyword. • SQL ORDER BY Syntax SELECT column_name, column_name FROM table_name ORDER BY column_name ASC|DESC, column_name ASC|DESC;
  • 10.  The SQL UPDATE Statement • The UPDATE statement is used to update existing records in a table. • SQL UPDATE Syntax UPDATE table_name SET column1=value1,column2=value2,... WHERE some_column=some_value;
  • 11.  The SQL DELETE Statement • The DELETE statement is used to delete rows in a table. • SQL DELETE Syntax DELETE FROM table_name WHERE some_column=some_value;
  • 12.  The SQL LIKE Operator • The LIKE operator is used to search for a specified pattern in a column. • SQL LIKE Syntax SELECT column_name(s) FROM table_name WHERE column_name LIKE pattern;
  • 13.  SQL Wildcard Characters In SQL, wildcard characters are used with the SQL LIKE operator. • SQL wildcards are used to search for data within a table. With SQL, the wildcards are: Wildcard Description % A substitute for zero or more characters _ A substitute for a single character [charlist] Sets and ranges of characters to match [!charlist] Matches only a character NOT specified within the brackets
  • 14.  SQL Joins • SQL joins are used to combine rows from two or more tables.
  • 15.  Different SQL JOINs • Before we continue with examples, we will list the types the different SQL JOINs you can use: • INNER JOIN: Returns all rows when there is at least one match in BOTH tables • LEFT JOIN: Return all rows from the left table, and the matched rows from the right table • RIGHT JOIN: Return all rows from the right table, and the matched rows from the left table • FULL JOIN: Return all rows when there is a match in ONE of the tables
  • 16.  SQL INNER JOIN Keyword • The INNER JOIN keyword selects all rows from both tables as long as there is a match between the columns in both tables. • SQL INNER JOIN Syntax SELECT column_name(s) FROM table1 INNER JOIN table2 ON table1.column_name=table2.column_name; or: • SELECT column_name(s) FROM table1 JOIN table2 ON table1.column_name=table2.column_name; PS! INNER JOIN is the same as JOIN.
  • 18.  SQL LEFT JOIN Keyword • The LEFT JOIN keyword returns all rows from the left table (table1), with the matching rows in the right table (table2). The result is NULL in the right side when there is no match. • SQL LEFT JOIN Syntax SELECT column_name(s) FROM table1 LEFT JOIN table2 ON table1.column_name=table2.column_name; or: • SELECT column_name(s) FROM table1 LEFT OUTER JOIN table2 ON table1.column_name=table2.column_name;
  • 20.  SQL RIGHT JOIN Keyword • The RIGHT JOIN keyword returns all rows from the right table (table2), with the matching rows in the left table (table1). The result is NULL in the left side when there is no match. • SQL RIGHT JOIN Syntax SELECT column_name(s) FROM table1 RIGHT JOIN table2 ON table1.column_name=table2.column_name; or: • SELECT column_name(s) FROM table1 RIGHT OUTER JOIN table2 ON table1.column_name=table2.column_name;
  • 22.  SQL FULL OUTER JOIN Keyword • The FULL OUTER JOIN keyword returns all rows from the left table (table1) and from the right table (table2). • The FULL OUTER JOIN keyword combines the result of both LEFT and RIGHT joins. • SQL FULL OUTER JOIN Syntax SELECT column_name(s) FROM table1 FULL OUTER JOIN table2 ON table1.column_name=table2.column_name;
  • 24.  The SQL CREATE TABLE Statement • The CREATE TABLE statement is used to create a table in a database. • Tables are organized into rows and columns; and each table must have a name. • SQL CREATE TABLE Syntax CREATE TABLE table_name ( column_name1 data_type(size), column_name2 data_type(size), column_name3 data_type(size), .... );
  • 25.  SQL Constraints SQL constraints are used to specify rules for the data in a table. • If there is any violation between the constraint and the data action, the action is aborted by the constraint. • Constraints can be specified when the table is created (inside the CREATE TABLE statement) or after the table is created (inside the ALTER TABLE statement). • SQL CREATE TABLE + CONSTRAINT Syntax CREATE TABLE table_name ( column_name1 data_type(size) constraint_name, column_name2 data_type(size) constraint_name, column_name3 data_type(size) constraint_name, .... );
  • 26.  In SQL, we have the following constraints: • NOT NULL - Indicates that a column cannot store NULL value • UNIQUE - Ensures that each row for a column must have a unique value • PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Ensures that a column (or combination of two or more columns) have an unique identity which helps to find a particular record in a table more easily and quickly • FOREIGN KEY - Ensure the referential integrity of the data in one table to match values in another table • CHECK - Ensures that the value in a column meets a specific condition • DEFAULT - Specifies a default value when specified none for this column
  • 27.  SQL Aggregate Functions • SQL aggregate functions return a single value, calculated from values in a column. • Useful aggregate functions: AVG() - Returns the average value COUNT() - Returns the number of rows FIRST() - Returns the first value LAST() - Returns the last value MAX() - Returns the largest value MIN() - Returns the smallest value SUM() - Returns the sum
  • 28.  SQL Scalar functions • SQL scalar functions return a single value, based on the input value. • Useful scalar functions: UCASE() - Converts a field to upper case LCASE() - Converts a field to lower case MID() - Extract characters from a text field LEN() - Returns the length of a text field ROUND() - Rounds a numeric field to the number of decimals specified NOW() - Returns the current system date and time FORMAT() - Formats how a field is to be displayed