SlideShare a Scribd company logo
SQL keywords and Functions
By: Ms. Rubab
Rubab.itc@suk-iba.edu.pk
IBA ITC Sobhodero
Managed By Khairpur Campus,
IBA Sukkur University
By: Ms. Rubab For DIT
The 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;
By: Ms. Rubab For DIT
Example
SELECT * FROM students
ORDER BY address ASC;
The above query selects all the students from student
table and sorts them in ascending order by their address
SELECT * FROM students
ORDER BY address DESC;
The above query selects all the students from student
table and sorts them in descending order by their address
SELECT * FROM Customers
ORDER BY address ASC, Name DESC;
The above query selects all the students from student
table and sorts them in ascending order by their address
and descending order by their names
By: Ms. Rubab For DIT
SQL NULL Values
A field with a NULL value is a field with no value.
If a field in a table is optional, it is possible to insert a
new record or update a record without adding a value to
this field. Then, the field will be saved with a NULL value.
Note: A NULL value is different from a zero value or a
field that contains spaces. A field with a NULL value is
one that has been left blank during record creation!
By: Ms. Rubab For DIT
How to test Null values
It is not possible to test for NULL values with comparison
operators, such as =, <, or <>.
We will have to use the IS NULL and IS NOT
NULL operators instead.
Syntax:
SELECT column_name(s)
FROM table_name
WHERE column_name IS NULL;
The IS NULL operator is used to test for empty values
(NULL values).
By: Ms. Rubab For DIT
IS NOT Null Syntax
SELECT column_names
FROM table_name
WHERE column_name IS NOT NULL;
The IS NOT NULL operator is used to test for non-empty
values (NOT NULL values).
Example:
SELECT * FROM students
Where address IS NOT NULL;
By: Ms. Rubab For DIT
SQL AS Keyword
The AS command is used to rename a column or table
with an alias.
NOTE:An alias only exists for the duration of the query.
Syntax:
SELECT column_name AS Alias, column2 AS Alias
FROM table_name
WHERE condition
By: Ms. Rubab For DIT
Example
SELECT fees AS STUDENT_FEES FROM students
By: Ms. Rubab For DIT
The SQL SELECT TOP Clause
The SELECT TOP clause is used to specify the number of
records to return.
The SELECT TOP clause is useful on large tables with
thousands of records. Returning a large number of
records can impact performance.
Syntax:
SELECT column_name(s)
FROM table_name
WHERE condition
LIMIT number;
By: Ms. Rubab For DIT
Example
SELECT ID,NAME
FROM students
WHERE ID<26
LIMIT 10
The above query selects top 10 records from
students table where id is less than 26
SELECT * FROM students.
LIMIT 3;
By: Ms. Rubab For DIT
SQL MIN() and MAX() Functions
The MIN() function returns the smallest value of the
selected column.
The MAX() function returns the largest value of the
selected column.
Min Syntax:
SELECT MIN(column_name)
FROM table_name
WHERE condition;
Max Syntax:
SELECT Max(column_name)
FROM table_name
WHERE condition;
By: Ms. Rubab For DIT
Examples
SELECT MIN(fees)
FROM students;
SELECT MAX(fees)
FROM students;
By: Ms. Rubab For DIT
SQL COUNT(), AVG() and
SUM() Functions
More SQL Functions
By: Ms. Rubab For DIT
SQL COUNT () Function
The COUNT() function returns the number of rows that
matches a specified criterion
Syntax:
SELECT COUNT(column_name)
FROM table_name
WHERE condition;
Example:
SELECT COUNT(ID)
FROM stuents;
By: Ms. Rubab For DIT
SQL AVG() Function
The AVG() function returns the average value of a
numeric column.
Syntax:
SELECT AVG(column_name)
FROM table_name
WHERE condition;
Example:
SELECT AVG(fees)
FROM students;
By: Ms. Rubab For DIT
SQL SUM() Function
The SUM() function returns the total sum of a numeric
column.
SELECT SUM(column_name)
FROM table_name
WHERE condition;
Example:
SELECT SUM(fees)
FROM students;
By: Ms. Rubab For DIT

More Related Content

PPTX
2 puc cs.pptx bsbshsjshsbbsjsjshdbdbbdbdd
PPTX
PPT
SQL || overview and detailed information about Sql
PPTX
Introduction to SQL
PPTX
Unit 3-Select Options and Aggregate Functions in SQL (1).pptx
PPT
SQL select statement and functions
PPTX
12. Basic SQL Queries (2).pptx
PDF
SQL Beginners anishurrehman.cloud.pdf
2 puc cs.pptx bsbshsjshsbbsjsjshdbdbbdbdd
SQL || overview and detailed information about Sql
Introduction to SQL
Unit 3-Select Options and Aggregate Functions in SQL (1).pptx
SQL select statement and functions
12. Basic SQL Queries (2).pptx
SQL Beginners anishurrehman.cloud.pdf

Similar to SQL Keywords and Functions.pptx (20)

PDF
full detailled SQL notesquestion bank (1).pdf
DOCX
SQL report
DOC
Complete Sql Server querries
PPT
DBMS-SQL-Commands-BBA-4-Sem-1-PanjabUniversity.ppt
PPT
SQL Presentation-1 (structured query language)
DOC
Learn sql queries
PPT
SQL Presentation-1 yehjebjj yeuu helo the worls.ppt
PPTX
06.01 sql select distinct
PDF
SQL Notes
PPTX
Database Overview
PDF
Sql (Introduction to Structured Query language)
PDF
SQL notes 1.pdf
PDF
Database Management System 1
PPTX
Its about a sql topic for basic structured query language
PPTX
DML using oracle
PPT
Mysql 120831075600-phpapp01
PPT
CE 279 - WRITING SQL QUERIES umat edition.ppt
PPTX
SQL Data Manipulation
PPT
MY SQL
DOCX
SQL Language
full detailled SQL notesquestion bank (1).pdf
SQL report
Complete Sql Server querries
DBMS-SQL-Commands-BBA-4-Sem-1-PanjabUniversity.ppt
SQL Presentation-1 (structured query language)
Learn sql queries
SQL Presentation-1 yehjebjj yeuu helo the worls.ppt
06.01 sql select distinct
SQL Notes
Database Overview
Sql (Introduction to Structured Query language)
SQL notes 1.pdf
Database Management System 1
Its about a sql topic for basic structured query language
DML using oracle
Mysql 120831075600-phpapp01
CE 279 - WRITING SQL QUERIES umat edition.ppt
SQL Data Manipulation
MY SQL
SQL Language
Ad

More from RUBAB79 (14)

DOCX
Database.docx
DOCX
RDBMS.docx
DOCX
MySQL String Functions.docx
DOCX
Difference between RDBMS and DBMS.docx
PPTX
Ms Access 1.pptx
PPTX
Lecture 4-RDBMS.pptx
PPTX
SQL Introduction.pptx
PPTX
SQL Operators.pptx
PPTX
SQL Commands Part 1.pptx
PPTX
Database Lecture 3.pptx
PPTX
SQL Conversion Functions.pptx
PPTX
SQL Commands Part 3.pptx
PPTX
SQL Commands Part 2.pptx
PPTX
DATABASE Lecture 1 and 2.pptx
Database.docx
RDBMS.docx
MySQL String Functions.docx
Difference between RDBMS and DBMS.docx
Ms Access 1.pptx
Lecture 4-RDBMS.pptx
SQL Introduction.pptx
SQL Operators.pptx
SQL Commands Part 1.pptx
Database Lecture 3.pptx
SQL Conversion Functions.pptx
SQL Commands Part 3.pptx
SQL Commands Part 2.pptx
DATABASE Lecture 1 and 2.pptx
Ad

Recently uploaded (20)

PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PPTX
Unit 4 Skeletal System.ppt.pptxopresentatiom
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PPTX
Lesson notes of climatology university.
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
IGGE1 Understanding the Self1234567891011
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PDF
Hazard Identification & Risk Assessment .pdf
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Digestion and Absorption of Carbohydrates, Proteina and Fats
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
Paper A Mock Exam 9_ Attempt review.pdf.
UNIT III MENTAL HEALTH NURSING ASSESSMENT
Final Presentation General Medicine 03-08-2024.pptx
Practical Manual AGRO-233 Principles and Practices of Natural Farming
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
Unit 4 Skeletal System.ppt.pptxopresentatiom
LDMMIA Reiki Yoga Finals Review Spring Summer
Lesson notes of climatology university.
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
What if we spent less time fighting change, and more time building what’s rig...
IGGE1 Understanding the Self1234567891011
Chinmaya Tiranga quiz Grand Finale.pdf
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
Hazard Identification & Risk Assessment .pdf
Computing-Curriculum for Schools in Ghana
Digestion and Absorption of Carbohydrates, Proteina and Fats
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...

SQL Keywords and Functions.pptx

  • 1. SQL keywords and Functions 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. The 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; By: Ms. Rubab For DIT
  • 3. Example SELECT * FROM students ORDER BY address ASC; The above query selects all the students from student table and sorts them in ascending order by their address SELECT * FROM students ORDER BY address DESC; The above query selects all the students from student table and sorts them in descending order by their address SELECT * FROM Customers ORDER BY address ASC, Name DESC; The above query selects all the students from student table and sorts them in ascending order by their address and descending order by their names By: Ms. Rubab For DIT
  • 4. SQL NULL Values A field with a NULL value is a field with no value. If a field in a table is optional, it is possible to insert a new record or update a record without adding a value to this field. Then, the field will be saved with a NULL value. Note: A NULL value is different from a zero value or a field that contains spaces. A field with a NULL value is one that has been left blank during record creation! By: Ms. Rubab For DIT
  • 5. How to test Null values It is not possible to test for NULL values with comparison operators, such as =, <, or <>. We will have to use the IS NULL and IS NOT NULL operators instead. Syntax: SELECT column_name(s) FROM table_name WHERE column_name IS NULL; The IS NULL operator is used to test for empty values (NULL values). By: Ms. Rubab For DIT
  • 6. IS NOT Null Syntax SELECT column_names FROM table_name WHERE column_name IS NOT NULL; The IS NOT NULL operator is used to test for non-empty values (NOT NULL values). Example: SELECT * FROM students Where address IS NOT NULL; By: Ms. Rubab For DIT
  • 7. SQL AS Keyword The AS command is used to rename a column or table with an alias. NOTE:An alias only exists for the duration of the query. Syntax: SELECT column_name AS Alias, column2 AS Alias FROM table_name WHERE condition By: Ms. Rubab For DIT
  • 8. Example SELECT fees AS STUDENT_FEES FROM students By: Ms. Rubab For DIT
  • 9. The SQL SELECT TOP Clause The SELECT TOP clause is used to specify the number of records to return. The SELECT TOP clause is useful on large tables with thousands of records. Returning a large number of records can impact performance. Syntax: SELECT column_name(s) FROM table_name WHERE condition LIMIT number; By: Ms. Rubab For DIT
  • 10. Example SELECT ID,NAME FROM students WHERE ID<26 LIMIT 10 The above query selects top 10 records from students table where id is less than 26 SELECT * FROM students. LIMIT 3; By: Ms. Rubab For DIT
  • 11. SQL MIN() and MAX() Functions The MIN() function returns the smallest value of the selected column. The MAX() function returns the largest value of the selected column. Min Syntax: SELECT MIN(column_name) FROM table_name WHERE condition; Max Syntax: SELECT Max(column_name) FROM table_name WHERE condition; By: Ms. Rubab For DIT
  • 12. Examples SELECT MIN(fees) FROM students; SELECT MAX(fees) FROM students; By: Ms. Rubab For DIT
  • 13. SQL COUNT(), AVG() and SUM() Functions More SQL Functions By: Ms. Rubab For DIT
  • 14. SQL COUNT () Function The COUNT() function returns the number of rows that matches a specified criterion Syntax: SELECT COUNT(column_name) FROM table_name WHERE condition; Example: SELECT COUNT(ID) FROM stuents; By: Ms. Rubab For DIT
  • 15. SQL AVG() Function The AVG() function returns the average value of a numeric column. Syntax: SELECT AVG(column_name) FROM table_name WHERE condition; Example: SELECT AVG(fees) FROM students; By: Ms. Rubab For DIT
  • 16. SQL SUM() Function The SUM() function returns the total sum of a numeric column. SELECT SUM(column_name) FROM table_name WHERE condition; Example: SELECT SUM(fees) FROM students; By: Ms. Rubab For DIT