SlideShare a Scribd company logo
1 of 16
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

Similar to SQL Keywords and Functions.pptx

ADBMS - Joins , Sorting , Distributed Database Systems
ADBMS - Joins , Sorting , Distributed Database SystemsADBMS - Joins , Sorting , Distributed Database Systems
ADBMS - Joins , Sorting , Distributed Database SystemsJoshua Costa
 
Database Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and deleteDatabase Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and deleteAl-Mamun Sarkar
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxjainendraKUMAR55
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functionsVikas Gupta
 
Chinabankppt
ChinabankpptChinabankppt
Chinabankpptnewrforce
 
Sql Basics | Edureka
Sql Basics | EdurekaSql Basics | Edureka
Sql Basics | EdurekaEdureka!
 
Data Manipulation Language.pptx
Data Manipulation Language.pptxData Manipulation Language.pptx
Data Manipulation Language.pptxEllenGracePorras
 
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
 
Sql server 2016 queries
Sql server 2016 queriesSql server 2016 queries
Sql server 2016 queriesSeyed Ibrahim
 
SQL Tutorial for Beginners
SQL Tutorial for BeginnersSQL Tutorial for Beginners
SQL Tutorial for BeginnersAbdelhay Shafi
 
Structured Query Language (SQL) Part 2.pptx
Structured Query Language (SQL) Part 2.pptxStructured Query Language (SQL) Part 2.pptx
Structured Query Language (SQL) Part 2.pptxEllenGracePorras
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETEAbrar ali
 
Sql intro
Sql introSql intro
Sql introglubox
 

Similar to SQL Keywords and Functions.pptx (20)

SQL PPT.pptx
SQL PPT.pptxSQL PPT.pptx
SQL PPT.pptx
 
ADBMS - Joins , Sorting , Distributed Database Systems
ADBMS - Joins , Sorting , Distributed Database SystemsADBMS - Joins , Sorting , Distributed Database Systems
ADBMS - Joins , Sorting , Distributed Database Systems
 
Database Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and deleteDatabase Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and delete
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptx
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
 
Query
QueryQuery
Query
 
Chinabankppt
ChinabankpptChinabankppt
Chinabankppt
 
Sql Basics | Edureka
Sql Basics | EdurekaSql Basics | Edureka
Sql Basics | Edureka
 
DBMS.pptx
DBMS.pptxDBMS.pptx
DBMS.pptx
 
Lab
LabLab
Lab
 
Data Manipulation Language.pptx
Data Manipulation Language.pptxData Manipulation Language.pptx
Data Manipulation Language.pptx
 
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)
 
DDL and DML statements.pptx
DDL and DML statements.pptxDDL and DML statements.pptx
DDL and DML statements.pptx
 
Sql server 2016 queries
Sql server 2016 queriesSql server 2016 queries
Sql server 2016 queries
 
SQL Tutorial for Beginners
SQL Tutorial for BeginnersSQL Tutorial for Beginners
SQL Tutorial for Beginners
 
Structured Query Language (SQL) Part 2.pptx
Structured Query Language (SQL) Part 2.pptxStructured Query Language (SQL) Part 2.pptx
Structured Query Language (SQL) Part 2.pptx
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
 
SQL
SQLSQL
SQL
 
unit-5 sql notes.docx
unit-5 sql notes.docxunit-5 sql notes.docx
unit-5 sql notes.docx
 
Sql intro
Sql introSql intro
Sql intro
 

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

Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
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
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 

Recently uploaded (20)

Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
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
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 

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