SlideShare a Scribd company logo
1 of 23
SQL Operators
By: Ms. Rubab
Rubab.itc@suk-iba.edu.pk
IBA ITC Sobhodero
Managed By Khairpur Campus,
IBA Sukkur University
By: Ms. Rubab For DIT
SQL Operators
Arthematic Operators
Bitwise Operators
Comparison Operators
Compound Operators
Logical Operators
By: Ms. Rubab For DIT
MySQL Arithmetic Operators
Operator Description Example Result
+ Add SELECT 30 + 20; 50
- Subtract SELECT 30 - 20; 10
* Multiply SELECT 30 * 10; 300
/ Divide SELECT 30 / 5; 6
% Modulo SELECT 30 % 5; 0
By: Ms. Rubab For DIT
Bitwise Operators
Operator Description
AND Bitwise AND
OR Bitwise OR
<> NOT
By: Ms. Rubab For DIT
Comparison Operators
Operator Description Example
= Equal to SELECT * FROM Products WHERE Price = 18;
> Greater than SELECT * FROM Products WHERE Price > 18;
< Less than SELECT * FROM Products WHERE Price < 18;
>= Greater than or equal to SELECT * FROM Products WHERE Price >= 18;
<= Less than or equal to SELECT * FROM Products WHERE Price <= 18;
<> Not equal to SELECT * FROM Products WHERE Price <> 18;
By: Ms. Rubab For DIT
MySQL
Compound
Operators
Operator Description
+= Add equals
-= Subtract equals
*= Multiply equals
/= Divide equals
%= Modulo equals
&= Bitwise AND equals
^-= Bitwise exclusive equals
|*= Bitwise OR equals
By: Ms. Rubab For DIT
MySQL
Logical
Operators
OPERATOR DESCRIPTION
ALL TRUE if all the subquery values meet the condition
AND TRUE if all the conditions separated by AND is TRUE
ANY TRUE if any of the subquery values meet the condition
BETWEEN TRUE if the operand is within the range of comparisons
EXISTS TRUE if the subquery returns one or more records
IN TRUE if the operand is equal to one of a list of
expressions
LIKE TRUE if the operand matches a pattern
NOT Displays a record if the condition(s) is NOT TRUE
OR TRUE if any of the conditions separated by OR is TRUE
SOME TRUE if any of the subquery values meet the condition
By: Ms. Rubab For DIT
SQL And , OR & NOT
The WHERE clause can be combined with AND, OR,
and NOT operators.
The AND and OR operators are used to filter records based
on more than one condition:
• The AND operator displays a record if all the conditions
separated by AND are TRUE.
• The OR operator displays a record if any of the
conditions separated by OR is TRUE.
• The NOT operator displays a record if the condition(s) is
NOT TRUE.
By: Ms. Rubab For DIT
AND syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition1 AND condition2 AND condition3 ...;
Example
SELECT ID, name,marks
FROM students
WHERE class=‘DIT-II’ AND Marks>=15;
By: Ms. Rubab For DIT
OR Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition1 OR condition2 OR condition3 ...;
Example
SELECT ID, name,marks
FROM students
WHERE class=‘DIT-II’ OR class=‘CIT’;
By: Ms. Rubab For DIT
NOT Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition1 NOT ;
Example
SELECT ID, name,marks
FROM students
WHERE NOT class=‘DIT-II’ ;
By: Ms. Rubab For DIT
Combining AND, OR and NOT
You can also combine the AND, OR and NOT operators.
Example:
SELECT * FROM studnets
WHERE marks>=15 AND (class=‘DIT-II' OR class=‘CIT’)
By: Ms. Rubab For DIT
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 sign (_) represents one, single character
Note: MS Access uses an asterisk (*) instead of the percent sign
(%), and a question mark (?) instead of the underscore (_).
The percent sign and the underscore can also be used in
combinations!
By: Ms. Rubab For DIT
LIKE Syntax
SELECT column1, column2, ...
FROM table_name
WHERE columnN LIKE pattern;
Example:
SELECT * FROM students
WHERE name LIKE '%a’;
This query will return all the students with names
ending with an a.
By: Ms. Rubab For DIT
More examples
SELECT * FROM students
WHERE name LIKE'%or%’;
This SQL statement selects all students with a name that
have "or" in any position
SELECT * FROM students
WHERE name LIKE’_a’;
This SQL statement selects all students with a name that
have “a" in the second position of their name
By: Ms. Rubab For DIT
Examples continued..
SELECT * FROM students
WHERE name LIKE’a__%’;
This SQL statement selects all students with name that
starts with ‘a’ and is atleast 3 characters long.
SELECT * FROM students
WHERE name LIKE’a%o’;
This SQL statement selects all students with name that
starts with ‘a’ and ends with ‘o’.
By: Ms. Rubab For DIT
More examples..
SELECT * FROM students
WHERE name NOT LIKE ‘a%’;
This SQL statement selects all students with name that
doesn't starts with ‘a’.
By: Ms. Rubab For DIT
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, ...);
By: Ms. Rubab For DIT
Examples
SELECT * FROM studets
WHERE address IN (‘sobhodero’,‘hinjorja’,’Naogoth’);
The above SQL statement selects all student that are
located in ‘sobhodero’, ‘hinjorja’, ’Naogoth’
SELECT * FROM students
WHERE address
NOT IN (‘sobhodero’,‘hinjorja’,’Naogoth’);
The above SQL statement selects all customers that are
not located in ‘sobhodero’, ‘hinjorja’, ’Naogoth’:
By: Ms. Rubab For DIT
SQL 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.
SYNTAX:
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
By: Ms. Rubab For DIT
Example
SELECT * FROM studnets
WHERE marks BETWEEN 10 AND 20;
This SQL statement selects all students with a marks
between 10 and 20:
SELECT * FROM studnets
WHERE marks NOT BETWEEN 10 AND 20;
This SQL statement selects all students with a marks
not between 10 and 20
By: Ms. Rubab For DIT
BETWEEN Text Values Example
SELECT * FROM students
WHERE name BETWEEN ’Amir’ AND ‘Zaheer’ ORDER BY ID;
The above query selects all the students names
between Amir and Zaheer and orders them by their ID
Number
By: Ms. Rubab For DIT
BETWEEN with IN Example
SELECT * FROM students
WHERE marks BETWEEN 10 AND 20
AND class NOT IN (‘DIT-I’,’CIT’);
This query returns all the students with marks
between 10 and 20 , and who are not in DIT-I and CIT
By: Ms. Rubab For DIT

More Related Content

Similar to SQL Operators.pptx

Statements,joins and operators in sql by thanveer danish melayi(1)
Statements,joins and operators in sql by thanveer danish melayi(1)Statements,joins and operators in sql by thanveer danish melayi(1)
Statements,joins and operators in sql by thanveer danish melayi(1)Muhammed Thanveer M
 
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
 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Trainingbixxman
 
8. OPERATORS IN SQL.pptx
8.  OPERATORS IN SQL.pptx8.  OPERATORS IN SQL.pptx
8. OPERATORS IN SQL.pptxRenugadeviR5
 
Where conditions and Operators in SQL
Where conditions and Operators in SQLWhere conditions and Operators in SQL
Where conditions and Operators in SQLRaajendra M
 
Where conditions and Operators in SQL
Where conditions and Operators in SQLWhere conditions and Operators in SQL
Where conditions and Operators in SQLMSB Academy
 
ORACLE, SQL, PL/SQL Made very very Easy Happy Learning....
ORACLE, SQL, PL/SQL Made very very Easy Happy Learning....ORACLE, SQL, PL/SQL Made very very Easy Happy Learning....
ORACLE, SQL, PL/SQL Made very very Easy Happy Learning....Racharla Rohit Varma
 
ALL ABOUT SQL AND RDBMS
ALL ABOUT SQL AND RDBMSALL ABOUT SQL AND RDBMS
ALL ABOUT SQL AND RDBMSgaurav koriya
 
Les02 (restricting and sorting data)
Les02 (restricting and sorting data)Les02 (restricting and sorting data)
Les02 (restricting and sorting data)Achmad Solichin
 
Restricting and sorting data
Restricting and sorting dataRestricting and sorting data
Restricting and sorting dataSyed Zaid Irshad
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functionsVikas Gupta
 

Similar to SQL Operators.pptx (20)

Practical 03 (1).pptx
Practical 03 (1).pptxPractical 03 (1).pptx
Practical 03 (1).pptx
 
Statements,joins and operators in sql by thanveer danish melayi(1)
Statements,joins and operators in sql by thanveer danish melayi(1)Statements,joins and operators in sql by thanveer danish melayi(1)
Statements,joins and operators in sql by thanveer danish melayi(1)
 
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)
 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Training
 
Lab1 select statement
Lab1 select statementLab1 select statement
Lab1 select statement
 
Sql2
Sql2Sql2
Sql2
 
8. OPERATORS IN SQL.pptx
8.  OPERATORS IN SQL.pptx8.  OPERATORS IN SQL.pptx
8. OPERATORS IN SQL.pptx
 
Oracle: Basic SQL
Oracle: Basic SQLOracle: Basic SQL
Oracle: Basic SQL
 
Oracle: Basic SQL
Oracle: Basic SQLOracle: Basic SQL
Oracle: Basic SQL
 
Where conditions and Operators in SQL
Where conditions and Operators in SQLWhere conditions and Operators in SQL
Where conditions and Operators in SQL
 
Where conditions and Operators in SQL
Where conditions and Operators in SQLWhere conditions and Operators in SQL
Where conditions and Operators in SQL
 
ORACLE, SQL, PL/SQL Made very very Easy Happy Learning....
ORACLE, SQL, PL/SQL Made very very Easy Happy Learning....ORACLE, SQL, PL/SQL Made very very Easy Happy Learning....
ORACLE, SQL, PL/SQL Made very very Easy Happy Learning....
 
Les18
Les18Les18
Les18
 
PL_SQL - II.pptx
PL_SQL - II.pptxPL_SQL - II.pptx
PL_SQL - II.pptx
 
ALL ABOUT SQL AND RDBMS
ALL ABOUT SQL AND RDBMSALL ABOUT SQL AND RDBMS
ALL ABOUT SQL AND RDBMS
 
V15 like operator-c
V15 like operator-cV15 like operator-c
V15 like operator-c
 
Les02 (restricting and sorting data)
Les02 (restricting and sorting data)Les02 (restricting and sorting data)
Les02 (restricting and sorting data)
 
Restricting and sorting data
Restricting and sorting dataRestricting and sorting data
Restricting and sorting data
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
 
Sql functions
Sql functionsSql functions
Sql functions
 

More from RUBAB79

Database.docx
Database.docxDatabase.docx
Database.docxRUBAB79
 
RDBMS.docx
RDBMS.docxRDBMS.docx
RDBMS.docxRUBAB79
 
MySQL String Functions.docx
MySQL String Functions.docxMySQL String Functions.docx
MySQL String Functions.docxRUBAB79
 
Difference between RDBMS and DBMS.docx
Difference between RDBMS and DBMS.docxDifference between RDBMS and DBMS.docx
Difference between RDBMS and DBMS.docxRUBAB79
 
Ms Access 1.pptx
Ms Access 1.pptxMs Access 1.pptx
Ms Access 1.pptxRUBAB79
 
Lecture 4-RDBMS.pptx
Lecture 4-RDBMS.pptxLecture 4-RDBMS.pptx
Lecture 4-RDBMS.pptxRUBAB79
 
SQL Introduction.pptx
SQL Introduction.pptxSQL Introduction.pptx
SQL Introduction.pptxRUBAB79
 
SQL Commands Part 1.pptx
SQL Commands Part 1.pptxSQL Commands Part 1.pptx
SQL Commands Part 1.pptxRUBAB79
 
Database Lecture 3.pptx
Database Lecture 3.pptxDatabase Lecture 3.pptx
Database Lecture 3.pptxRUBAB79
 
SQL Conversion Functions.pptx
SQL Conversion Functions.pptxSQL Conversion Functions.pptx
SQL Conversion Functions.pptxRUBAB79
 
SQL Commands Part 3.pptx
SQL Commands Part 3.pptxSQL Commands Part 3.pptx
SQL Commands Part 3.pptxRUBAB79
 
SQL Commands Part 2.pptx
SQL Commands Part 2.pptxSQL Commands Part 2.pptx
SQL Commands Part 2.pptxRUBAB79
 
DATABASE Lecture 1 and 2.pptx
DATABASE Lecture 1 and 2.pptxDATABASE Lecture 1 and 2.pptx
DATABASE Lecture 1 and 2.pptxRUBAB79
 

More from RUBAB79 (13)

Database.docx
Database.docxDatabase.docx
Database.docx
 
RDBMS.docx
RDBMS.docxRDBMS.docx
RDBMS.docx
 
MySQL String Functions.docx
MySQL String Functions.docxMySQL String Functions.docx
MySQL String Functions.docx
 
Difference between RDBMS and DBMS.docx
Difference between RDBMS and DBMS.docxDifference between RDBMS and DBMS.docx
Difference between RDBMS and DBMS.docx
 
Ms Access 1.pptx
Ms Access 1.pptxMs Access 1.pptx
Ms Access 1.pptx
 
Lecture 4-RDBMS.pptx
Lecture 4-RDBMS.pptxLecture 4-RDBMS.pptx
Lecture 4-RDBMS.pptx
 
SQL Introduction.pptx
SQL Introduction.pptxSQL Introduction.pptx
SQL Introduction.pptx
 
SQL Commands Part 1.pptx
SQL Commands Part 1.pptxSQL Commands Part 1.pptx
SQL Commands Part 1.pptx
 
Database Lecture 3.pptx
Database Lecture 3.pptxDatabase Lecture 3.pptx
Database Lecture 3.pptx
 
SQL Conversion Functions.pptx
SQL Conversion Functions.pptxSQL Conversion Functions.pptx
SQL Conversion Functions.pptx
 
SQL Commands Part 3.pptx
SQL Commands Part 3.pptxSQL Commands Part 3.pptx
SQL Commands Part 3.pptx
 
SQL Commands Part 2.pptx
SQL Commands Part 2.pptxSQL Commands Part 2.pptx
SQL Commands Part 2.pptx
 
DATABASE Lecture 1 and 2.pptx
DATABASE Lecture 1 and 2.pptxDATABASE Lecture 1 and 2.pptx
DATABASE Lecture 1 and 2.pptx
 

Recently uploaded

ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........LeaCamillePacle
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayMakMakNepo
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationAadityaSharma884161
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 

Recently uploaded (20)

ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up Friday
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint Presentation
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 

SQL Operators.pptx

  • 1. SQL Operators By: Ms. Rubab Rubab.itc@suk-iba.edu.pk IBA ITC Sobhodero Managed By Khairpur Campus, IBA Sukkur University By: Ms. Rubab For DIT
  • 2. SQL Operators Arthematic Operators Bitwise Operators Comparison Operators Compound Operators Logical Operators By: Ms. Rubab For DIT
  • 3. MySQL Arithmetic Operators Operator Description Example Result + Add SELECT 30 + 20; 50 - Subtract SELECT 30 - 20; 10 * Multiply SELECT 30 * 10; 300 / Divide SELECT 30 / 5; 6 % Modulo SELECT 30 % 5; 0 By: Ms. Rubab For DIT
  • 4. Bitwise Operators Operator Description AND Bitwise AND OR Bitwise OR <> NOT By: Ms. Rubab For DIT
  • 5. Comparison Operators Operator Description Example = Equal to SELECT * FROM Products WHERE Price = 18; > Greater than SELECT * FROM Products WHERE Price > 18; < Less than SELECT * FROM Products WHERE Price < 18; >= Greater than or equal to SELECT * FROM Products WHERE Price >= 18; <= Less than or equal to SELECT * FROM Products WHERE Price <= 18; <> Not equal to SELECT * FROM Products WHERE Price <> 18; By: Ms. Rubab For DIT
  • 6. MySQL Compound Operators Operator Description += Add equals -= Subtract equals *= Multiply equals /= Divide equals %= Modulo equals &= Bitwise AND equals ^-= Bitwise exclusive equals |*= Bitwise OR equals By: Ms. Rubab For DIT
  • 7. MySQL Logical Operators OPERATOR DESCRIPTION ALL TRUE if all the subquery values meet the condition AND TRUE if all the conditions separated by AND is TRUE ANY TRUE if any of the subquery values meet the condition BETWEEN TRUE if the operand is within the range of comparisons EXISTS TRUE if the subquery returns one or more records IN TRUE if the operand is equal to one of a list of expressions LIKE TRUE if the operand matches a pattern NOT Displays a record if the condition(s) is NOT TRUE OR TRUE if any of the conditions separated by OR is TRUE SOME TRUE if any of the subquery values meet the condition By: Ms. Rubab For DIT
  • 8. SQL And , OR & NOT The WHERE clause can be combined with AND, OR, and NOT operators. The AND and OR operators are used to filter records based on more than one condition: • The AND operator displays a record if all the conditions separated by AND are TRUE. • The OR operator displays a record if any of the conditions separated by OR is TRUE. • The NOT operator displays a record if the condition(s) is NOT TRUE. By: Ms. Rubab For DIT
  • 9. AND syntax SELECT column1, column2, ... FROM table_name WHERE condition1 AND condition2 AND condition3 ...; Example SELECT ID, name,marks FROM students WHERE class=‘DIT-II’ AND Marks>=15; By: Ms. Rubab For DIT
  • 10. OR Syntax SELECT column1, column2, ... FROM table_name WHERE condition1 OR condition2 OR condition3 ...; Example SELECT ID, name,marks FROM students WHERE class=‘DIT-II’ OR class=‘CIT’; By: Ms. Rubab For DIT
  • 11. NOT Syntax SELECT column1, column2, ... FROM table_name WHERE condition1 NOT ; Example SELECT ID, name,marks FROM students WHERE NOT class=‘DIT-II’ ; By: Ms. Rubab For DIT
  • 12. Combining AND, OR and NOT You can also combine the AND, OR and NOT operators. Example: SELECT * FROM studnets WHERE marks>=15 AND (class=‘DIT-II' OR class=‘CIT’) By: Ms. Rubab For DIT
  • 13. 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 sign (_) represents one, single character Note: MS Access uses an asterisk (*) instead of the percent sign (%), and a question mark (?) instead of the underscore (_). The percent sign and the underscore can also be used in combinations! By: Ms. Rubab For DIT
  • 14. LIKE Syntax SELECT column1, column2, ... FROM table_name WHERE columnN LIKE pattern; Example: SELECT * FROM students WHERE name LIKE '%a’; This query will return all the students with names ending with an a. By: Ms. Rubab For DIT
  • 15. More examples SELECT * FROM students WHERE name LIKE'%or%’; This SQL statement selects all students with a name that have "or" in any position SELECT * FROM students WHERE name LIKE’_a’; This SQL statement selects all students with a name that have “a" in the second position of their name By: Ms. Rubab For DIT
  • 16. Examples continued.. SELECT * FROM students WHERE name LIKE’a__%’; This SQL statement selects all students with name that starts with ‘a’ and is atleast 3 characters long. SELECT * FROM students WHERE name LIKE’a%o’; This SQL statement selects all students with name that starts with ‘a’ and ends with ‘o’. By: Ms. Rubab For DIT
  • 17. More examples.. SELECT * FROM students WHERE name NOT LIKE ‘a%’; This SQL statement selects all students with name that doesn't starts with ‘a’. By: Ms. Rubab For DIT
  • 18. 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, ...); By: Ms. Rubab For DIT
  • 19. Examples SELECT * FROM studets WHERE address IN (‘sobhodero’,‘hinjorja’,’Naogoth’); The above SQL statement selects all student that are located in ‘sobhodero’, ‘hinjorja’, ’Naogoth’ SELECT * FROM students WHERE address NOT IN (‘sobhodero’,‘hinjorja’,’Naogoth’); The above SQL statement selects all customers that are not located in ‘sobhodero’, ‘hinjorja’, ’Naogoth’: By: Ms. Rubab For DIT
  • 20. SQL 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. SYNTAX: SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value1 AND value2; By: Ms. Rubab For DIT
  • 21. Example SELECT * FROM studnets WHERE marks BETWEEN 10 AND 20; This SQL statement selects all students with a marks between 10 and 20: SELECT * FROM studnets WHERE marks NOT BETWEEN 10 AND 20; This SQL statement selects all students with a marks not between 10 and 20 By: Ms. Rubab For DIT
  • 22. BETWEEN Text Values Example SELECT * FROM students WHERE name BETWEEN ’Amir’ AND ‘Zaheer’ ORDER BY ID; The above query selects all the students names between Amir and Zaheer and orders them by their ID Number By: Ms. Rubab For DIT
  • 23. BETWEEN with IN Example SELECT * FROM students WHERE marks BETWEEN 10 AND 20 AND class NOT IN (‘DIT-I’,’CIT’); This query returns all the students with marks between 10 and 20 , and who are not in DIT-I and CIT By: Ms. Rubab For DIT