SlideShare a Scribd company logo
SQL
STUCTURED Query Language
Where it is Used?
O It is used to manipulate and maintain Databases with queries.
O This can be benefited on integrating with other programming
languages such as PHP, Python, C, .NET etc
O Examples:-
 SELECT `password` FROM `table_login` WHERE
`username`=‘somevalue’;
 UPDATE table_name SET column1=value1,column2=value2,...
WHERE some_column=some_value;
 SELECT column_name FROM table_name
WHERE column_name BETWEEN value1 AND value2;
Some Query Keywords
O SELECT - extracts data from a database
O UPDATE - updates data in a database
O DELETE - deletes data from a database
O INSERT INTO - inserts new data into a database
O CREATE DATABASE - creates a new database
O ALTER DATABASE - modifies a database
O CREATE TABLE - creates a new table
O ALTER TABLE - modifies a table
O DROP TABLE - deletes a table
O CREATE INDEX - creates an index (search key)
O DROP INDEX - deletes an index
The SQL SELECT Statement
O The SELECT statement is used to select data from a
database.
O The result is stored in a result table, called the
result-set.
O SQL SELECT Syntax
O SELECT column_name,column_name
FROM table_name; and
O SELECT * FROM table_name;
The SQL SELECT DISTINCT Statement
O In a table, a column may contain many duplicate
values; and sometimes you only want to list the
different (distinct) values.
O The DISTINCT keyword can be used to return only
distinct (different) values.
O SQL SELECT DISTINCT Syntax
O SELECT DISTINCT column_name,column_name
FROM table_name;
The SQL WHERE Clause
O The WHERE clause is used to extract only
those records that fulfill a specified
criterion.
O SQL WHERE Syntax
O SELECT column_name,column_name
FROM table_name
WHERE column_name operator value;
The SQL AND & OR Operators
O The AND & OR operators are used to filter
records based on more than one condition.
O The AND operator displays a record if both
the first condition AND the second condition
are true.
O The OR operator displays a record if either
the first condition OR the second condition
is true.
SQL ORDER BY Keyword
O The ORDER BY keyword is used to sort the result-set by
one or more columns.
O 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.
O SQL ORDER BY Syntax
O SELECT column_name, column_name
FROM table_name
ORDER BY column_name ASC|DESC, column_name ASC|DESC;
SQL INSERT INTO Statement
O The INSERT INTO statement is used to insert new
records in a table.
O SQL INSERT INTO Syntax
O It is possible to write the INSERT INTO statement
in two forms.
O The first form does not specify the column names
where the data will be inserted, only their values:
O INSERT INTO table_name
VALUES (value1,value2,value3,...);
O The second form specifies both the column names and
the values to be inserted:
O INSERT INTO table_name (column1,column2,column3,...)
VALUES (value1,value2,value3,...);
SQL UPDATE Statement
O The UPDATE statement is used to update
existing records in a table.
O SQL UPDATE Syntax
O UPDATE table_nameSET column1=value1,column2=v
alue2,...WHERE some_column=some_value;
O Notice the WHERE clause in the SQL UPDATE
statement!
The WHERE clause specifies which record or
records that should be updated. If you omit
the WHERE clause, all records will be
updated!
SQL DELETE Statement
O The DELETE statement is used to delete
records in a table.
O The SQL DELETE Statement
O The DELETE statement is used to delete rows
in a table.
O SQL DELETE Syntax
O DELETE FROM table_name
WHERE some_column=some_value;
O Notice the WHERE clause in the SQL DELETE
statement!
The WHERE clause specifies which record or
records that should be deleted. If you omit
the WHERE clause, all records will be
deleted!
The IN Operator
O The IN operator allows you to specify
multiple values in a WHERE clause.
O SQL IN Syntax
O SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1,value2,...);
O
SQL BETWEEN Operator
O The BETWEEN operator selects values within a
range. The values can be numbers, text, or
dates.
O SQL BETWEEN Syntax
O SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value
2;
SQL JOIN
O An SQL JOIN clause is used to combine rows from two or more tables,
based on a common field between them.
O Example:
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate FROM
Orders INNER JOIN Customers
ON Orders.CustomerID=Customers.CustomerID;
O INNER JOIN: Returns all rows when there is at least one match in
BOTH tables
O LEFT JOIN: Return all rows from the left table, and the matched rows
from the right table
O RIGHT JOIN: Return all rows from the right table, and the matched
rows from the left table
O FULL JOIN: Return all rows when there is a match in ONE of the
tables
SQL UNION Operator
O The UNION operator is used to combine the result-set of
two or more SELECT statements.
O Notice that each SELECT statement within the UNION must
have the same number of columns. The columns must also
have similar data types. Also, the columns in each SELECT
statement must be in the same order.
O SQL UNION Syntax:
O SELECT column_name(s) FROM table1
UNION
SELECT column_name(s) FROM table2;
SQL SELECT INTO Syntax
O We can copy all columns into the new table:
O SELECT *
INTO newtable [IN externaldb]
FROM table1;
O Or we can copy only the columns we want into the
new table:
O SELECT column_name(s)
INTO newtable [IN externaldb]
FROM table1;
SQL CREATE DATABASE Syntax
O Syntax:
O CREATE DATABASE dbname;
O Database tables can be added with the CREATE
TABLE statement.
The SQL CREATE TABLE
Statement
O CREATE TABLE table_name(
column_name1 data_type(size),
column_name2 data_type(size),
column_name3 data_type(size),
....);
O The column_name parameters specify the names of the
columns of the table.
O The data_type parameter specifies what type of data the
column can hold (e.g. varchar, integer, decimal, date,
etc.).
O The size parameter specifies the maximum length of the
column of the table.
DROP INDEX Statement
O The DROP TABLE Statement
O The DROP TABLE statement is used to delete a table.
O DROP TABLE table_name
O The DROP DATABASE Statement
O The DROP DATABASE statement is used to delete a
database.
O DROP DATABASE database_name
O The TRUNCATE TABLE Statement
O What if we only want to delete the data inside the
table, and not the table itself?
O Then, use the TRUNCATE TABLE statement:
O TRUNCATE TABLE table_name
The ALTER TABLE Statement
O SQL ALTER TABLE Syntax
O To add a column in a table, use the following
syntax:
O ALTER TABLE table_name
ADD column_name datatype
O To delete a column in a table, use the
following syntax (notice that some database
systems don't allow deleting a column):
O ALTER TABLE table_name
DROP COLUMN column_name
-Thank You!

More Related Content

PPT
Sql basics and DDL statements
PPT
Concurrencia 2 ABD UCV
PPTX
Oraclesql
PDF
Postgre sql
PDF
Transacciones y sql procedural EN MySQL
PPTX
PPTX
PL/SQL Fundamentals I
PPTX
Tarjetas crc
Sql basics and DDL statements
Concurrencia 2 ABD UCV
Oraclesql
Postgre sql
Transacciones y sql procedural EN MySQL
PL/SQL Fundamentals I
Tarjetas crc

What's hot (20)

PPTX
Types of keys in dbms
PPTX
5. stored procedure and functions
PPT
SQL Tutorial - Basic Commands
PPTX
Comandos básicos mysql
PPTX
TRIGGERS O DISPARADORES
PPT
Normalization
PPTX
Sistema de informacion
PDF
View & index in SQL
PPTX
MySQL Basics
PPTX
Tipos de usuarios de base de datos diapositivas
PDF
Aprenda SQL Server
PPTX
sql function(ppt)
DOCX
Diccionario de datos
PDF
Transiciones de Procesos
PPTX
Procedimientos almacenados
PPTX
Sql operator
PDF
Nested Queries Lecture
PPT
PL/SQL
PPTX
Capitulo 13 diseño de bases de datos - analisis y diseño de sistemas. Kendal...
PPSX
Sistemas distribuidos
Types of keys in dbms
5. stored procedure and functions
SQL Tutorial - Basic Commands
Comandos básicos mysql
TRIGGERS O DISPARADORES
Normalization
Sistema de informacion
View & index in SQL
MySQL Basics
Tipos de usuarios de base de datos diapositivas
Aprenda SQL Server
sql function(ppt)
Diccionario de datos
Transiciones de Procesos
Procedimientos almacenados
Sql operator
Nested Queries Lecture
PL/SQL
Capitulo 13 diseño de bases de datos - analisis y diseño de sistemas. Kendal...
Sistemas distribuidos
Ad

Viewers also liked (18)

PDF
Assignment2
PDF
SQL Functions and Operators
PDF
Dicas de Planejamento & Estratégia de Comunicação e Marketing, por Rô Villa...
PPTX
MODULO 4
PDF
Буктрейлер
PDF
Pursueasia global connexio 1
DOC
Advertisment Fallacies in the United States
PPTX
MODULO 2
PPTX
Logic development
PDF
Makalah epidemiologi kel5
PDF
Eleições 2016 - Gestão e Inteligência no Marketing Político e Eleitoral
PPT
Sql operators & functions 3
PDF
Tomato-based products
PPT
The Power of Self Belief
PPT
Major Genetically Modified Crops
PPT
Sql ppt
PPT
โครงการระบบป้องกันน้ำท่วมรังสิต
Assignment2
SQL Functions and Operators
Dicas de Planejamento & Estratégia de Comunicação e Marketing, por Rô Villa...
MODULO 4
Буктрейлер
Pursueasia global connexio 1
Advertisment Fallacies in the United States
MODULO 2
Logic development
Makalah epidemiologi kel5
Eleições 2016 - Gestão e Inteligência no Marketing Político e Eleitoral
Sql operators & functions 3
Tomato-based products
The Power of Self Belief
Major Genetically Modified Crops
Sql ppt
โครงการระบบป้องกันน้ำท่วมรังสิต
Ad

Similar to SQL (20)

PDF
full detailled SQL notesquestion bank (1).pdf
PPTX
DOCX
PPTX
Sql slid
PPTX
SQL Query
PPTX
SQL Tutorial for Beginners
PPTX
SQl data base management and design
PPTX
DOCX
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
PPT
Mysql 120831075600-phpapp01
PPT
MY SQL
PDF
SQL Beginners anishurrehman.cloud.pdf
PPTX
Sql commands
PPTX
PPTX
DBMS and SQL(structured query language) .pptx
PDF
Sql overview-1232931296681161-1
PPT
Interactive SQL: SQL, Features of SQL, DDL & DML
PPT
1 introduction to my sql
PPTX
Lab1 select statement
PPTX
Creating database using sql commands
full detailled SQL notesquestion bank (1).pdf
Sql slid
SQL Query
SQL Tutorial for Beginners
SQl data base management and design
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Mysql 120831075600-phpapp01
MY SQL
SQL Beginners anishurrehman.cloud.pdf
Sql commands
DBMS and SQL(structured query language) .pptx
Sql overview-1232931296681161-1
Interactive SQL: SQL, Features of SQL, DDL & DML
1 introduction to my sql
Lab1 select statement
Creating database using sql commands

Recently uploaded (20)

PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Cell Types and Its function , kingdom of life
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Computing-Curriculum for Schools in Ghana
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Institutional Correction lecture only . . .
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Basic Mud Logging Guide for educational purpose
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Cell Types and Its function , kingdom of life
Anesthesia in Laparoscopic Surgery in India
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Final Presentation General Medicine 03-08-2024.pptx
Computing-Curriculum for Schools in Ghana
Microbial disease of the cardiovascular and lymphatic systems
Institutional Correction lecture only . . .
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
O5-L3 Freight Transport Ops (International) V1.pdf
PPH.pptx obstetrics and gynecology in nursing
GDM (1) (1).pptx small presentation for students
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Renaissance Architecture: A Journey from Faith to Humanism
VCE English Exam - Section C Student Revision Booklet
Basic Mud Logging Guide for educational purpose
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
TR - Agricultural Crops Production NC III.pdf

SQL

  • 2. Where it is Used? O It is used to manipulate and maintain Databases with queries. O This can be benefited on integrating with other programming languages such as PHP, Python, C, .NET etc O Examples:-  SELECT `password` FROM `table_login` WHERE `username`=‘somevalue’;  UPDATE table_name SET column1=value1,column2=value2,... WHERE some_column=some_value;  SELECT column_name FROM table_name WHERE column_name BETWEEN value1 AND value2;
  • 3. Some Query Keywords O SELECT - extracts data from a database O UPDATE - updates data in a database O DELETE - deletes data from a database O INSERT INTO - inserts new data into a database O CREATE DATABASE - creates a new database O ALTER DATABASE - modifies a database O CREATE TABLE - creates a new table O ALTER TABLE - modifies a table O DROP TABLE - deletes a table O CREATE INDEX - creates an index (search key) O DROP INDEX - deletes an index
  • 4. The SQL SELECT Statement O The SELECT statement is used to select data from a database. O The result is stored in a result table, called the result-set. O SQL SELECT Syntax O SELECT column_name,column_name FROM table_name; and O SELECT * FROM table_name;
  • 5. The SQL SELECT DISTINCT Statement O In a table, a column may contain many duplicate values; and sometimes you only want to list the different (distinct) values. O The DISTINCT keyword can be used to return only distinct (different) values. O SQL SELECT DISTINCT Syntax O SELECT DISTINCT column_name,column_name FROM table_name;
  • 6. The SQL WHERE Clause O The WHERE clause is used to extract only those records that fulfill a specified criterion. O SQL WHERE Syntax O SELECT column_name,column_name FROM table_name WHERE column_name operator value;
  • 7. The SQL AND & OR Operators O The AND & OR operators are used to filter records based on more than one condition. O The AND operator displays a record if both the first condition AND the second condition are true. O The OR operator displays a record if either the first condition OR the second condition is true.
  • 8. SQL ORDER BY Keyword O The ORDER BY keyword is used to sort the result-set by one or more columns. O 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. O SQL ORDER BY Syntax O SELECT column_name, column_name FROM table_name ORDER BY column_name ASC|DESC, column_name ASC|DESC;
  • 9. SQL INSERT INTO Statement O The INSERT INTO statement is used to insert new records in a table. O SQL INSERT INTO Syntax O It is possible to write the INSERT INTO statement in two forms. O The first form does not specify the column names where the data will be inserted, only their values: O INSERT INTO table_name VALUES (value1,value2,value3,...); O The second form specifies both the column names and the values to be inserted: O INSERT INTO table_name (column1,column2,column3,...) VALUES (value1,value2,value3,...);
  • 10. SQL UPDATE Statement O The UPDATE statement is used to update existing records in a table. O SQL UPDATE Syntax O UPDATE table_nameSET column1=value1,column2=v alue2,...WHERE some_column=some_value; O Notice the WHERE clause in the SQL UPDATE statement! The WHERE clause specifies which record or records that should be updated. If you omit the WHERE clause, all records will be updated!
  • 11. SQL DELETE Statement O The DELETE statement is used to delete records in a table. O The SQL DELETE Statement O The DELETE statement is used to delete rows in a table. O SQL DELETE Syntax O DELETE FROM table_name WHERE some_column=some_value; O Notice the WHERE clause in the SQL DELETE statement! The WHERE clause specifies which record or records that should be deleted. If you omit the WHERE clause, all records will be deleted!
  • 12. The IN Operator O The IN operator allows you to specify multiple values in a WHERE clause. O SQL IN Syntax O SELECT column_name(s) FROM table_name WHERE column_name IN (value1,value2,...); O
  • 13. SQL BETWEEN Operator O The BETWEEN operator selects values within a range. The values can be numbers, text, or dates. O SQL BETWEEN Syntax O SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value1 AND value 2;
  • 14. SQL JOIN O An SQL JOIN clause is used to combine rows from two or more tables, based on a common field between them. O Example: SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate FROM Orders INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID; O INNER JOIN: Returns all rows when there is at least one match in BOTH tables O LEFT JOIN: Return all rows from the left table, and the matched rows from the right table O RIGHT JOIN: Return all rows from the right table, and the matched rows from the left table O FULL JOIN: Return all rows when there is a match in ONE of the tables
  • 15. SQL UNION Operator O The UNION operator is used to combine the result-set of two or more SELECT statements. O Notice that each SELECT statement within the UNION must have the same number of columns. The columns must also have similar data types. Also, the columns in each SELECT statement must be in the same order. O SQL UNION Syntax: O SELECT column_name(s) FROM table1 UNION SELECT column_name(s) FROM table2;
  • 16. SQL SELECT INTO Syntax O We can copy all columns into the new table: O SELECT * INTO newtable [IN externaldb] FROM table1; O Or we can copy only the columns we want into the new table: O SELECT column_name(s) INTO newtable [IN externaldb] FROM table1;
  • 17. SQL CREATE DATABASE Syntax O Syntax: O CREATE DATABASE dbname; O Database tables can be added with the CREATE TABLE statement.
  • 18. The SQL CREATE TABLE Statement O CREATE TABLE table_name( column_name1 data_type(size), column_name2 data_type(size), column_name3 data_type(size), ....); O The column_name parameters specify the names of the columns of the table. O The data_type parameter specifies what type of data the column can hold (e.g. varchar, integer, decimal, date, etc.). O The size parameter specifies the maximum length of the column of the table.
  • 19. DROP INDEX Statement O The DROP TABLE Statement O The DROP TABLE statement is used to delete a table. O DROP TABLE table_name O The DROP DATABASE Statement O The DROP DATABASE statement is used to delete a database. O DROP DATABASE database_name O The TRUNCATE TABLE Statement O What if we only want to delete the data inside the table, and not the table itself? O Then, use the TRUNCATE TABLE statement: O TRUNCATE TABLE table_name
  • 20. The ALTER TABLE Statement O SQL ALTER TABLE Syntax O To add a column in a table, use the following syntax: O ALTER TABLE table_name ADD column_name datatype O To delete a column in a table, use the following syntax (notice that some database systems don't allow deleting a column): O ALTER TABLE table_name DROP COLUMN column_name