SlideShare a Scribd company logo
1 of 28
Download to read offline
Introduction to Structured
Query Language
(SQL)
Assistant Lecturer Huda A. Alameen
hudaa.alameen@uokufa.edu.iq
SQL
 SQL stands for Structured Query Language. SQL is used to
communicate with a database. According to ANSI (American National
Standards Institute), it is the standard language for relational
database management systems.
 SQL is based on set and relational operations with certain
modifications and enhancements
SQL select statement
 retrieving data from the database by specifying which columns and rows to be
retrieved
 The basics syntax for select statement is :
SELECT column1, column2, …….
FROM table
SELECT column1, column2, …….
FROM table
Example
SQL SELECT DISTINCT Statement
 The SELECT DISTINCT statement is used to return only distinct (different)
values.
 Inside a table, a column often contains many duplicate values; and sometimes
you only want to list the different (distinct) values.
 SELECT DISTINCT Syntax
SELECT DISTINCT column1, column2, ...
FROM table_name;
Example
SELECT DISTINCT Country FROM Customers;
Country
Germany
UK
Sweden
WHERE
 Commonly 3 clauses (SELECT, FROM, WHERE) are used
 Query: List the names of the capital cities in the CITY
table.
SQL and, or Syntax
 The syntax for and condition is:
 The syntax for and condition is:
SELECT column1, column2, …….
FROM table
WHERE condition1 AND condition2 AND condition3 ...;
SELECT column1, column2, ...
FROM table_name
WHERE condition1 OR condition2 OR condition3 ...;
Not Syntax
SELECT column1, column2, ...
FROM table_name
WHERE NOT condition;
Examples
SELECT * FROM Customers
WHERE Country='Germany' AND City='Berlin';
SELECT * FROM Customers
WHERE Country='Germany' AND (City='Berlin' OR City='München');
SQL ORDER BY Keyword
 The ORDER BY keyword is used to sort the result-set in ascending or
descending order.
 The ORDER BY keyword sorts the records in ascending order by default. To
sort the records in descending order, use the DESC keyword.
 ORDER BY Syntax
SELECT column1, column2, ...
FROM table_name
ORDER BY column1, column2, ... ASC|DESC;
Examples
Examples
SELECT * FROM Customers
ORDER BY Country;
SELECT * FROM Customers
ORDER BY Country DESC;
SELECT * FROM Customers
ORDER BY Country, CustomerName;
SELECT * FROM Customers
ORDER BY Country ASC, CustomerName DESC;
SQL LIKE Operator
 The LIKE operator is used in a WHERE clause to search for a specified pattern
in a column.
 There are two wildcards often used in conjunction with the LIKE operator:
 % - The percent sign represents zero, one, or multiple characters
 _ - The underscore represents a single character
 LIKE Syntax
SELECT column1, column2, ...
FROM table_name
WHERE columnN LIKE pattern;
SQL LIKE Operator
Examples
Examples
SQL IN Operator
 The IN operator allows you to specify multiple values in a WHERE clause.
 The IN operator is a shorthand for multiple OR conditions.
 IN Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1, value2, ...);
 or:
SELECT column_name(s)
FROM table_name
WHERE column_name IN (SELECT STATEMENT);
SELECT * FROM Customers
WHERE Country IN ('Germany', 'France', 'UK');
SELECT * FROM Customers
WHERE Country NOT IN ('Germany', 'France', 'UK');
BETWEEN Operator
 The BETWEEN operator selects values within a given range. The values can be
numbers, text, or dates.
 The BETWEEN operator is inclusive: begin and end values are included.
 BETWEEN Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
Example
SELECT * FROM Products
WHERE Price BETWEEN 10 AND 20;
Examples
Employee (Ename,DepartmentID,Salary)
Department(DepartmentID, DepartmentName)
1- Select all employees with EName that starts with “R”
Ans:
SELECT * FROM Employees WHERE EName LIKE ’R%’
2- Select all employees with EName that contains “R”
Ans:
SELECT * FROM Employees WHERE EName LIKE ’%R%’
3- Select all students with Sname ending with “J”
Ans:
SELECT * FROM Employees WHERE EName LIKE ’%J’
Examples
4- Select employees in departments number 31,34 and 35
Ans:
SELECT * FROM Employees WHERE DepartmentId IN (31,34,35)
5- Select employees that works in a department
Ans:
SELECT * FROM Employees WHERE DepartmentId IN (SELECT DepartmentID FROM
Department)
6-Select employees that earn salaries between 1000 and 2000 dollar
Ans:
Select * from Employees WHERE Salary BETWEEN 1000 AND 2000
Introduction to structured query language

More Related Content

What's hot (18)

2.2 sql commands
2.2 sql commands2.2 sql commands
2.2 sql commands
 
SQL
SQLSQL
SQL
 
Sql commands
Sql commandsSql commands
Sql commands
 
Lecture 3 sql {basics ddl commands}
Lecture 3 sql {basics  ddl commands}Lecture 3 sql {basics  ddl commands}
Lecture 3 sql {basics ddl commands}
 
SQL MCQ
SQL MCQSQL MCQ
SQL MCQ
 
SQL Tutorial for Beginners
SQL Tutorial for BeginnersSQL Tutorial for Beginners
SQL Tutorial for Beginners
 
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}
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
 
Sql basics v2
Sql basics v2Sql basics v2
Sql basics v2
 
MY SQL
MY SQLMY SQL
MY SQL
 
Db1 lecture4
Db1 lecture4Db1 lecture4
Db1 lecture4
 
Higher SQL
Higher SQLHigher SQL
Higher SQL
 
Entigrity constraint
Entigrity constraintEntigrity constraint
Entigrity constraint
 
Exploring collections with example
Exploring collections with exampleExploring collections with example
Exploring collections with example
 
Babitha2.mysql
Babitha2.mysqlBabitha2.mysql
Babitha2.mysql
 
C introduction
C introductionC introduction
C introduction
 
Sql Tags
Sql TagsSql Tags
Sql Tags
 
oracle Sql constraint
oracle  Sql constraint oracle  Sql constraint
oracle Sql constraint
 

Similar to Introduction to structured query language

SQL Beginners anishurrehman.cloud.pdf
SQL Beginners anishurrehman.cloud.pdfSQL Beginners anishurrehman.cloud.pdf
SQL Beginners anishurrehman.cloud.pdfAnishurRehman1
 
ADV Powepoint 2 Lec.pptx
ADV Powepoint 2 Lec.pptxADV Powepoint 2 Lec.pptx
ADV Powepoint 2 Lec.pptxArjayBalberan1
 
Beginers guide for oracle sql
Beginers guide for oracle sqlBeginers guide for oracle sql
Beginers guide for oracle sqlN.Jagadish Kumar
 
ADV Powepoint 3 Lec.pptx
ADV Powepoint 3 Lec.pptxADV Powepoint 3 Lec.pptx
ADV Powepoint 3 Lec.pptxArjayBalberan1
 
ADV Powepoint 4 Lec.pptx
ADV Powepoint 4 Lec.pptxADV Powepoint 4 Lec.pptx
ADV Powepoint 4 Lec.pptxArjayBalberan1
 
Introduction to sql new
Introduction to sql newIntroduction to sql new
Introduction to sql newSANTOSH RATH
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functionsVikas Gupta
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic ConceptsTony Wong
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries InformationNishant Munjal
 
Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)Achmad Solichin
 

Similar to Introduction to structured query language (20)

SQL Beginners anishurrehman.cloud.pdf
SQL Beginners anishurrehman.cloud.pdfSQL Beginners anishurrehman.cloud.pdf
SQL Beginners anishurrehman.cloud.pdf
 
SQL
SQLSQL
SQL
 
ADV Powepoint 2 Lec.pptx
ADV Powepoint 2 Lec.pptxADV Powepoint 2 Lec.pptx
ADV Powepoint 2 Lec.pptx
 
Lab1 select statement
Lab1 select statementLab1 select statement
Lab1 select statement
 
Sql 2006
Sql 2006Sql 2006
Sql 2006
 
012. SQL.pdf
012. SQL.pdf012. SQL.pdf
012. SQL.pdf
 
Sql
SqlSql
Sql
 
SQL
SQLSQL
SQL
 
Beginers guide for oracle sql
Beginers guide for oracle sqlBeginers guide for oracle sql
Beginers guide for oracle sql
 
ADV Powepoint 3 Lec.pptx
ADV Powepoint 3 Lec.pptxADV Powepoint 3 Lec.pptx
ADV Powepoint 3 Lec.pptx
 
ADV Powepoint 4 Lec.pptx
ADV Powepoint 4 Lec.pptxADV Powepoint 4 Lec.pptx
ADV Powepoint 4 Lec.pptx
 
Query
QueryQuery
Query
 
Introduction to sql new
Introduction to sql newIntroduction to sql new
Introduction to sql new
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
 
SQL
SQLSQL
SQL
 
Dbms
DbmsDbms
Dbms
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic Concepts
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries Information
 
Sql
SqlSql
Sql
 
Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)
 

More from Huda Alameen

More from Huda Alameen (20)

Architectural design
Architectural designArchitectural design
Architectural design
 
System Modeling
System ModelingSystem Modeling
System Modeling
 
Requirements Engineering
Requirements EngineeringRequirements Engineering
Requirements Engineering
 
Java Repetiotion Statements
Java Repetiotion StatementsJava Repetiotion Statements
Java Repetiotion Statements
 
Java input Scanner
Java input Scanner Java input Scanner
Java input Scanner
 
Java Print method
Java  Print methodJava  Print method
Java Print method
 
Softweare Engieering
Softweare Engieering Softweare Engieering
Softweare Engieering
 
Softweare Engieering
Softweare Engieering Softweare Engieering
Softweare Engieering
 
Structured query language(sql)
Structured query language(sql)Structured query language(sql)
Structured query language(sql)
 
Sql viwes
Sql viwesSql viwes
Sql viwes
 
Relational algebra
Relational algebraRelational algebra
Relational algebra
 
Normalization
NormalizationNormalization
Normalization
 
Lecture one db
Lecture one dbLecture one db
Lecture one db
 
Indexing techniques
Indexing techniquesIndexing techniques
Indexing techniques
 
Agg fun
Agg funAgg fun
Agg fun
 
Se lec1 (1)
Se lec1 (1)Se lec1 (1)
Se lec1 (1)
 
Se lec6
Se lec6Se lec6
Se lec6
 
Se lec5
Se lec5Se lec5
Se lec5
 
Se lec 4
Se lec 4Se lec 4
Se lec 4
 
Se lec 3
Se lec 3Se lec 3
Se lec 3
 

Recently uploaded

Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTSérgio Sacani
 
A relative description on Sonoporation.pdf
A relative description on Sonoporation.pdfA relative description on Sonoporation.pdf
A relative description on Sonoporation.pdfnehabiju2046
 
Raman spectroscopy.pptx M Pharm, M Sc, Advanced Spectral Analysis
Raman spectroscopy.pptx M Pharm, M Sc, Advanced Spectral AnalysisRaman spectroscopy.pptx M Pharm, M Sc, Advanced Spectral Analysis
Raman spectroscopy.pptx M Pharm, M Sc, Advanced Spectral AnalysisDiwakar Mishra
 
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCE
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCESTERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCE
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCEPRINCE C P
 
Isotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoIsotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoSérgio Sacani
 
Biopesticide (2).pptx .This slides helps to know the different types of biop...
Biopesticide (2).pptx  .This slides helps to know the different types of biop...Biopesticide (2).pptx  .This slides helps to know the different types of biop...
Biopesticide (2).pptx .This slides helps to know the different types of biop...RohitNehra6
 
Boyles law module in the grade 10 science
Boyles law module in the grade 10 scienceBoyles law module in the grade 10 science
Boyles law module in the grade 10 sciencefloriejanemacaya1
 
Artificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C PArtificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C PPRINCE C P
 
Cultivation of KODO MILLET . made by Ghanshyam pptx
Cultivation of KODO MILLET . made by Ghanshyam pptxCultivation of KODO MILLET . made by Ghanshyam pptx
Cultivation of KODO MILLET . made by Ghanshyam pptxpradhanghanshyam7136
 
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroidsHubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroidsSérgio Sacani
 
Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )aarthirajkumar25
 
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxSOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxkessiyaTpeter
 
Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?Patrick Diehl
 
Spermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatidSpermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatidSarthak Sekhar Mondal
 
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...jana861314
 
GFP in rDNA Technology (Biotechnology).pptx
GFP in rDNA Technology (Biotechnology).pptxGFP in rDNA Technology (Biotechnology).pptx
GFP in rDNA Technology (Biotechnology).pptxAleenaTreesaSaji
 
Botany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfBotany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfSumit Kumar yadav
 
Broad bean, Lima Bean, Jack bean, Ullucus.pptx
Broad bean, Lima Bean, Jack bean, Ullucus.pptxBroad bean, Lima Bean, Jack bean, Ullucus.pptx
Broad bean, Lima Bean, Jack bean, Ullucus.pptxjana861314
 
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Sérgio Sacani
 

Recently uploaded (20)

The Philosophy of Science
The Philosophy of ScienceThe Philosophy of Science
The Philosophy of Science
 
Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOST
 
A relative description on Sonoporation.pdf
A relative description on Sonoporation.pdfA relative description on Sonoporation.pdf
A relative description on Sonoporation.pdf
 
Raman spectroscopy.pptx M Pharm, M Sc, Advanced Spectral Analysis
Raman spectroscopy.pptx M Pharm, M Sc, Advanced Spectral AnalysisRaman spectroscopy.pptx M Pharm, M Sc, Advanced Spectral Analysis
Raman spectroscopy.pptx M Pharm, M Sc, Advanced Spectral Analysis
 
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCE
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCESTERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCE
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCE
 
Isotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoIsotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on Io
 
Biopesticide (2).pptx .This slides helps to know the different types of biop...
Biopesticide (2).pptx  .This slides helps to know the different types of biop...Biopesticide (2).pptx  .This slides helps to know the different types of biop...
Biopesticide (2).pptx .This slides helps to know the different types of biop...
 
Boyles law module in the grade 10 science
Boyles law module in the grade 10 scienceBoyles law module in the grade 10 science
Boyles law module in the grade 10 science
 
Artificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C PArtificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C P
 
Cultivation of KODO MILLET . made by Ghanshyam pptx
Cultivation of KODO MILLET . made by Ghanshyam pptxCultivation of KODO MILLET . made by Ghanshyam pptx
Cultivation of KODO MILLET . made by Ghanshyam pptx
 
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroidsHubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
 
Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )
 
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxSOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
 
Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?
 
Spermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatidSpermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatid
 
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
 
GFP in rDNA Technology (Biotechnology).pptx
GFP in rDNA Technology (Biotechnology).pptxGFP in rDNA Technology (Biotechnology).pptx
GFP in rDNA Technology (Biotechnology).pptx
 
Botany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfBotany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdf
 
Broad bean, Lima Bean, Jack bean, Ullucus.pptx
Broad bean, Lima Bean, Jack bean, Ullucus.pptxBroad bean, Lima Bean, Jack bean, Ullucus.pptx
Broad bean, Lima Bean, Jack bean, Ullucus.pptx
 
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
 

Introduction to structured query language

  • 1. Introduction to Structured Query Language (SQL) Assistant Lecturer Huda A. Alameen hudaa.alameen@uokufa.edu.iq
  • 2. SQL  SQL stands for Structured Query Language. SQL is used to communicate with a database. According to ANSI (American National Standards Institute), it is the standard language for relational database management systems.  SQL is based on set and relational operations with certain modifications and enhancements
  • 3. SQL select statement  retrieving data from the database by specifying which columns and rows to be retrieved  The basics syntax for select statement is : SELECT column1, column2, ……. FROM table SELECT column1, column2, ……. FROM table
  • 4.
  • 6. SQL SELECT DISTINCT Statement  The SELECT DISTINCT statement is used to return only distinct (different) values.  Inside a table, a column often contains many duplicate values; and sometimes you only want to list the different (distinct) values.  SELECT DISTINCT Syntax SELECT DISTINCT column1, column2, ... FROM table_name;
  • 7. Example SELECT DISTINCT Country FROM Customers; Country Germany UK Sweden
  • 8. WHERE  Commonly 3 clauses (SELECT, FROM, WHERE) are used  Query: List the names of the capital cities in the CITY table.
  • 9.
  • 10. SQL and, or Syntax  The syntax for and condition is:  The syntax for and condition is: SELECT column1, column2, ……. FROM table WHERE condition1 AND condition2 AND condition3 ...; SELECT column1, column2, ... FROM table_name WHERE condition1 OR condition2 OR condition3 ...;
  • 11. Not Syntax SELECT column1, column2, ... FROM table_name WHERE NOT condition;
  • 12.
  • 13. Examples SELECT * FROM Customers WHERE Country='Germany' AND City='Berlin'; SELECT * FROM Customers WHERE Country='Germany' AND (City='Berlin' OR City='München');
  • 14. SQL ORDER BY Keyword  The ORDER BY keyword is used to sort the result-set in ascending or descending order.  The ORDER BY keyword sorts the records in ascending order by default. To sort the records in descending order, use the DESC keyword.  ORDER BY Syntax SELECT column1, column2, ... FROM table_name ORDER BY column1, column2, ... ASC|DESC;
  • 16. Examples SELECT * FROM Customers ORDER BY Country; SELECT * FROM Customers ORDER BY Country DESC; SELECT * FROM Customers ORDER BY Country, CustomerName; SELECT * FROM Customers ORDER BY Country ASC, CustomerName DESC;
  • 17. SQL LIKE Operator  The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.  There are two wildcards often used in conjunction with the LIKE operator:  % - The percent sign represents zero, one, or multiple characters  _ - The underscore represents a single character  LIKE Syntax SELECT column1, column2, ... FROM table_name WHERE columnN LIKE pattern;
  • 21. SQL IN Operator  The IN operator allows you to specify multiple values in a WHERE clause.  The IN operator is a shorthand for multiple OR conditions.  IN Syntax SELECT column_name(s) FROM table_name WHERE column_name IN (value1, value2, ...);  or: SELECT column_name(s) FROM table_name WHERE column_name IN (SELECT STATEMENT);
  • 22. SELECT * FROM Customers WHERE Country IN ('Germany', 'France', 'UK');
  • 23. SELECT * FROM Customers WHERE Country NOT IN ('Germany', 'France', 'UK');
  • 24. BETWEEN Operator  The BETWEEN operator selects values within a given range. The values can be numbers, text, or dates.  The BETWEEN operator is inclusive: begin and end values are included.  BETWEEN Syntax SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value1 AND value2;
  • 25. Example SELECT * FROM Products WHERE Price BETWEEN 10 AND 20;
  • 26. Examples Employee (Ename,DepartmentID,Salary) Department(DepartmentID, DepartmentName) 1- Select all employees with EName that starts with “R” Ans: SELECT * FROM Employees WHERE EName LIKE ’R%’ 2- Select all employees with EName that contains “R” Ans: SELECT * FROM Employees WHERE EName LIKE ’%R%’ 3- Select all students with Sname ending with “J” Ans: SELECT * FROM Employees WHERE EName LIKE ’%J’
  • 27. Examples 4- Select employees in departments number 31,34 and 35 Ans: SELECT * FROM Employees WHERE DepartmentId IN (31,34,35) 5- Select employees that works in a department Ans: SELECT * FROM Employees WHERE DepartmentId IN (SELECT DepartmentID FROM Department) 6-Select employees that earn salaries between 1000 and 2000 dollar Ans: Select * from Employees WHERE Salary BETWEEN 1000 AND 2000