SlideShare a Scribd company logo
1 of 28
RDBMS
SQL CLAUSES
Lecture Slide by:- Manan Pasricha
Student of Bachelor of Computer Applications
E-mail id: pasrichamanan81@gmail.com
LinkedIn Profile:- https://www.linkedin.com/in/manan-pasricha-76029818a/
CONTENTS
01 Distinct Clause
03 Order By Clause
04 Group By Clause
05 Having Clause
02 Where Clause
1.
Distinct Clause
Distinct Clause
The SQL DISTINCT keyword is used in conjunction with the SELECT statement to eliminate all the duplicate
records and fetching only unique records.
There may be a situation when you have multiple duplicate records in a table. While fetching such records, it
makes more sense to fetch only those unique records instead of fetching duplicate records.
What is distinct clause?
Syntax
The basic syntax of DISTINCT keyword to eliminate the duplicate records is as follows:
SELECT DISTINCT column1, column2,.....column FROM table_name WHERE [condition];
Distinct Clause
Consider the CUSTOMERS table having the following records:
Example 1
Distinct Clause
First, let us see how the following SELECT query returns the duplicate salary records.
SQL> SELECT SALARY FROM CUSTOMERS ORDER BY SALARY;
This would produce the following result, where the salary (2000) is coming twice which is a duplicate record
from the original table.
Example 1(Continued)
Distinct Clause
Now, let us use the DISTINCT keyword with the above SELECT query and then see the
result.
SQL> SELECT DISTINCT SALARY FROM CUSTOMERS ORDER BY SALARY;
This would produce the following result where we do not have any duplicate entry.
Example 1(Continued)
2.
Where Clause
Where Clause
The SQL WHERE clause is used to specify a condition while fetching the data from a single table or by joining with
multiple tables. If the given condition is satisfied, then only it returns a specific value from the table. You should use
the WHERE clause to filter the records and fetching only the necessary records.
The WHERE clause is not only used in the SELECT statement, but it is also used in the UPDATE, DELETE
statement, etc.,
What is where clause?
Syntax
The basic syntax of the SELECT statement with the WHERE clause is:
SELECT column1, column2, column FROM table_name WHERE [condition];
You can specify a condition using the comparison or logical operators like >, <, =, LIKE,
NOT, etc. The following examples would make this concept clear.
Where Clause
Consider the CUSTOMERS table having the following records:
Example 1
Where Clause
The following code is an example which would fetch the ID, Name and Salary fields from the CUSTOMERS
table, where the salary is greater than 2000:
SQL> SELECT ID, NAME, SALARY FROM CUSTOMERS WHERE SALARY > 2000;
This would produce the following result:
Example 1(Continued)
Where Clause
Again considering the same CUSTOMERS table and lets take an another query, which would fetch the ID, Name
and Salary fields from the CUSTOMERS table for a customer with the name Hardik.
NOTE: Here, it is important to note that all the strings should be given inside single quotes (''). Whereas, numeric
values should be given without any quote as in the above example.
SQL> SELECT ID, NAME, SALARY FROM CUSTOMERS WHERE NAME = 'Hardik';
This would produce the following result:
Example 2
3.
Order By Clause
Order By Clause
The SQL ORDER BY clause is used to sort the data in ascending or descending order,
based on one or more columns. Some databases sort the query results in an ascending
order by default.
What is order by clause?
Syntax
The basic syntax of the ORDER BY clause is as follows:
SELECT column-list FROM table_name [WHERE condition] [ORDER BY column1, column2, .. columnN]
[ASC | DESC];
You can use more than one column in the ORDER BY clause. Make sure whatever column
you are using to sort that column should be in the column-list.
Order By Clause
Consider the CUSTOMERS table having the following records:
Example 1
Order By Clause
The following code block has an example, which would sort the result in an ascending
order by the NAME and the SALARY.
SQL> SELECT * FROM CUSTOMERS ORDER BY NAME, SALARY;
This would produce the following result:
Example 1(Continued)
Order By Clause
Again considering the same CUSTOMERS table and lets take an another query, which would sort the result in the
descending order by NAME.
SQL> SELECT * FROM CUSTOMERS ORDER BY NAME DESC;
This would produce the following result:
Example 2
4.
Group By Clause
Group By Clause
The SQL GROUP BY clause is used in collaboration with the SELECT statement to arrange identical data into
groups. This GROUP BY clause follows the WHERE clause in a SELECT statement and precedes the ORDER
BY clause.
What is Group By clause?
Syntax
The basic syntax of a GROUP BY clause is shown in the following code block. The GROUP BY clause must
follow the conditions in the WHERE clause and must precede the ORDER BY clause if one is used.
SELECT column1, group_Fuction(column2) FROM table_name WHERE [ conditions ] GROUP BY column1,
column2 ORDER BY column1, column2;
Group By Clause
Consider the CUSTOMERS table having the following records:
Example 1
Group By Clause
If you want to know the total amount of the salary on each customer, then the GROUP BY
query would be as follows.
SQL> SELECT NAME, SUM(SALARY) FROM CUSTOMERS GROUP BY NAME;
This would produce the following result:
Example 1(Continued)
Group By Clause
Now, let us look at a table where the CUSTOMERS table has the following records with
duplicate names:
Example 2
Group By Clause
Now again, if you want to know the total amount of salary on each customer, then the GROUP BY query would
be as follows:
SQL> SELECT NAME, SUM(SALARY) FROM CUSTOMERS GROUP BY NAME;
This would produce the following result:
Example 2(Continued)
5.
Having Clause
Having Clause
The HAVING Clause enables you to specify conditions that filter which group results
appear in the results.
The WHERE clause places conditions on the selected columns, whereas the HAVING clause
places conditions on groups created by the GROUP BY clause.
What is Having clause?
Syntax
The HAVING clause must follow the GROUP BY clause in a query and must also precede the ORDER BY clause
if used. The following code block has the syntax of the SELECT statement including the HAVING clause:
SELECT column1, column2 FROM table1, table2 WHERE [ conditions ] GROUP BY column1, column2
HAVING [ conditions ] ORDER BY column1, column2;
Having Clause
Consider the CUSTOMERS table having the following records:
Example
Having Clause
Following is an example, which would display a record for a similar age count that would
be more than or equal to 2.
SQL > SELECT ID, NAME, AGE, ADDRESS, SALARY FROM CUSTOMERS GROUP BY age HAVING COUNT(age) >= 2;
This would produce the following result:
Example(Continued)
THANKS for watching
Lecture Slide by:- Manan Pasricha
Student of Bachelor of Computer Applications
E-mail id: pasrichamanan81@gmail.com
LinkedIn Profile:- https://www.linkedin.com/in/manan-
pasricha-76029818a/

More Related Content

What's hot (20)

Working with Databases and MySQL
Working with Databases and MySQLWorking with Databases and MySQL
Working with Databases and MySQL
 
Sql commands
Sql commandsSql commands
Sql commands
 
SQL subquery
SQL subquerySQL subquery
SQL subquery
 
Basic sql Commands
Basic sql CommandsBasic sql Commands
Basic sql Commands
 
Sql subquery
Sql  subquerySql  subquery
Sql subquery
 
Mysql
MysqlMysql
Mysql
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
Aggregate function
Aggregate functionAggregate function
Aggregate function
 
MySQL
MySQLMySQL
MySQL
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
 
5. stored procedure and functions
5. stored procedure and functions5. stored procedure and functions
5. stored procedure and functions
 
PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts
 
Manipulating Data Oracle Data base
Manipulating Data Oracle Data baseManipulating Data Oracle Data base
Manipulating Data Oracle Data base
 
SQL DDL
SQL DDLSQL DDL
SQL DDL
 
Mysql Crud, Php Mysql, php, sql
Mysql Crud, Php Mysql, php, sqlMysql Crud, Php Mysql, php, sql
Mysql Crud, Php Mysql, php, sql
 
SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
 
Oracle basic queries
Oracle basic queriesOracle basic queries
Oracle basic queries
 
Single row functions
Single row functionsSingle row functions
Single row functions
 

Similar to Sql clauses by Manan Pasricha

Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic ConceptsTony Wong
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commandsBelle Wx
 
Aggregate Functions,Final
Aggregate Functions,FinalAggregate Functions,Final
Aggregate Functions,Finalmukesh24pandey
 
PPT of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
PPT  of Common Table Expression (CTE), Window Functions, JOINS, SubQueryPPT  of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
PPT of Common Table Expression (CTE), Window Functions, JOINS, SubQueryAbhishek590097
 
Module 3.1.pptx
Module 3.1.pptxModule 3.1.pptx
Module 3.1.pptxANSHVAJPAI
 
Group by clause mod
Group by clause modGroup by clause mod
Group by clause modNitesh Singh
 
SQL Beginners anishurrehman.cloud.pdf
SQL Beginners anishurrehman.cloud.pdfSQL Beginners anishurrehman.cloud.pdf
SQL Beginners anishurrehman.cloud.pdfAnishurRehman1
 
Unit 3-Select Options and Aggregate Functions in SQL (1).pptx
Unit 3-Select Options and Aggregate Functions in SQL (1).pptxUnit 3-Select Options and Aggregate Functions in SQL (1).pptx
Unit 3-Select Options and Aggregate Functions in SQL (1).pptxHAMEEDHUSSAINBU21CSE
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSabrinaShanta2
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSaiMiryala1
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxBhupendraShahi6
 

Similar to Sql clauses by Manan Pasricha (20)

Sql wksht-6
Sql wksht-6Sql wksht-6
Sql wksht-6
 
Sql query [select, sub] 4
Sql query [select, sub] 4Sql query [select, sub] 4
Sql query [select, sub] 4
 
Query
QueryQuery
Query
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic Concepts
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
 
chapter 8 SQL.ppt
chapter 8 SQL.pptchapter 8 SQL.ppt
chapter 8 SQL.ppt
 
Sql ch 5
Sql ch 5Sql ch 5
Sql ch 5
 
SQL Query
SQL QuerySQL Query
SQL Query
 
Aggregate Functions,Final
Aggregate Functions,FinalAggregate Functions,Final
Aggregate Functions,Final
 
Oraclesql
OraclesqlOraclesql
Oraclesql
 
PPT of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
PPT  of Common Table Expression (CTE), Window Functions, JOINS, SubQueryPPT  of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
PPT of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
 
Module 3.1.pptx
Module 3.1.pptxModule 3.1.pptx
Module 3.1.pptx
 
Group by clause mod
Group by clause modGroup by clause mod
Group by clause mod
 
SQL Beginners anishurrehman.cloud.pdf
SQL Beginners anishurrehman.cloud.pdfSQL Beginners anishurrehman.cloud.pdf
SQL Beginners anishurrehman.cloud.pdf
 
MYSql manage db
MYSql manage dbMYSql manage db
MYSql manage db
 
Clauses in sql server
Clauses in sql serverClauses in sql server
Clauses in sql server
 
Unit 3-Select Options and Aggregate Functions in SQL (1).pptx
Unit 3-Select Options and Aggregate Functions in SQL (1).pptxUnit 3-Select Options and Aggregate Functions in SQL (1).pptx
Unit 3-Select Options and Aggregate Functions in SQL (1).pptx
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
 

Recently uploaded

fitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptfitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptAfnanAhmad53
 
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...josephjonse
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...Amil baba
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...HenryBriggs2
 
Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)ChandrakantDivate1
 
Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257subhasishdas79
 
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesLinux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesRashidFaridChishti
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARKOUSTAV SARKAR
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"mphochane1998
 
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...ronahami
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 
Post office management system project ..pdf
Post office management system project ..pdfPost office management system project ..pdf
Post office management system project ..pdfKamal Acharya
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network DevicesChandrakantDivate1
 
8086 Microprocessor Architecture: 16-bit microprocessor
8086 Microprocessor Architecture: 16-bit microprocessor8086 Microprocessor Architecture: 16-bit microprocessor
8086 Microprocessor Architecture: 16-bit microprocessorAshwiniTodkar4
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxSCMS School of Architecture
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdfKamal Acharya
 
Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...ppkakm
 

Recently uploaded (20)

fitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptfitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .ppt
 
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
Signal Processing and Linear System Analysis
Signal Processing and Linear System AnalysisSignal Processing and Linear System Analysis
Signal Processing and Linear System Analysis
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)
 
Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257
 
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesLinux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Post office management system project ..pdf
Post office management system project ..pdfPost office management system project ..pdf
Post office management system project ..pdf
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
8086 Microprocessor Architecture: 16-bit microprocessor
8086 Microprocessor Architecture: 16-bit microprocessor8086 Microprocessor Architecture: 16-bit microprocessor
8086 Microprocessor Architecture: 16-bit microprocessor
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...
 

Sql clauses by Manan Pasricha

  • 1. RDBMS SQL CLAUSES Lecture Slide by:- Manan Pasricha Student of Bachelor of Computer Applications E-mail id: pasrichamanan81@gmail.com LinkedIn Profile:- https://www.linkedin.com/in/manan-pasricha-76029818a/
  • 2. CONTENTS 01 Distinct Clause 03 Order By Clause 04 Group By Clause 05 Having Clause 02 Where Clause
  • 4. Distinct Clause The SQL DISTINCT keyword is used in conjunction with the SELECT statement to eliminate all the duplicate records and fetching only unique records. There may be a situation when you have multiple duplicate records in a table. While fetching such records, it makes more sense to fetch only those unique records instead of fetching duplicate records. What is distinct clause? Syntax The basic syntax of DISTINCT keyword to eliminate the duplicate records is as follows: SELECT DISTINCT column1, column2,.....column FROM table_name WHERE [condition];
  • 5. Distinct Clause Consider the CUSTOMERS table having the following records: Example 1
  • 6. Distinct Clause First, let us see how the following SELECT query returns the duplicate salary records. SQL> SELECT SALARY FROM CUSTOMERS ORDER BY SALARY; This would produce the following result, where the salary (2000) is coming twice which is a duplicate record from the original table. Example 1(Continued)
  • 7. Distinct Clause Now, let us use the DISTINCT keyword with the above SELECT query and then see the result. SQL> SELECT DISTINCT SALARY FROM CUSTOMERS ORDER BY SALARY; This would produce the following result where we do not have any duplicate entry. Example 1(Continued)
  • 9. Where Clause The SQL WHERE clause is used to specify a condition while fetching the data from a single table or by joining with multiple tables. If the given condition is satisfied, then only it returns a specific value from the table. You should use the WHERE clause to filter the records and fetching only the necessary records. The WHERE clause is not only used in the SELECT statement, but it is also used in the UPDATE, DELETE statement, etc., What is where clause? Syntax The basic syntax of the SELECT statement with the WHERE clause is: SELECT column1, column2, column FROM table_name WHERE [condition]; You can specify a condition using the comparison or logical operators like >, <, =, LIKE, NOT, etc. The following examples would make this concept clear.
  • 10. Where Clause Consider the CUSTOMERS table having the following records: Example 1
  • 11. Where Clause The following code is an example which would fetch the ID, Name and Salary fields from the CUSTOMERS table, where the salary is greater than 2000: SQL> SELECT ID, NAME, SALARY FROM CUSTOMERS WHERE SALARY > 2000; This would produce the following result: Example 1(Continued)
  • 12. Where Clause Again considering the same CUSTOMERS table and lets take an another query, which would fetch the ID, Name and Salary fields from the CUSTOMERS table for a customer with the name Hardik. NOTE: Here, it is important to note that all the strings should be given inside single quotes (''). Whereas, numeric values should be given without any quote as in the above example. SQL> SELECT ID, NAME, SALARY FROM CUSTOMERS WHERE NAME = 'Hardik'; This would produce the following result: Example 2
  • 14. Order By Clause The SQL ORDER BY clause is used to sort the data in ascending or descending order, based on one or more columns. Some databases sort the query results in an ascending order by default. What is order by clause? Syntax The basic syntax of the ORDER BY clause is as follows: SELECT column-list FROM table_name [WHERE condition] [ORDER BY column1, column2, .. columnN] [ASC | DESC]; You can use more than one column in the ORDER BY clause. Make sure whatever column you are using to sort that column should be in the column-list.
  • 15. Order By Clause Consider the CUSTOMERS table having the following records: Example 1
  • 16. Order By Clause The following code block has an example, which would sort the result in an ascending order by the NAME and the SALARY. SQL> SELECT * FROM CUSTOMERS ORDER BY NAME, SALARY; This would produce the following result: Example 1(Continued)
  • 17. Order By Clause Again considering the same CUSTOMERS table and lets take an another query, which would sort the result in the descending order by NAME. SQL> SELECT * FROM CUSTOMERS ORDER BY NAME DESC; This would produce the following result: Example 2
  • 19. Group By Clause The SQL GROUP BY clause is used in collaboration with the SELECT statement to arrange identical data into groups. This GROUP BY clause follows the WHERE clause in a SELECT statement and precedes the ORDER BY clause. What is Group By clause? Syntax The basic syntax of a GROUP BY clause is shown in the following code block. The GROUP BY clause must follow the conditions in the WHERE clause and must precede the ORDER BY clause if one is used. SELECT column1, group_Fuction(column2) FROM table_name WHERE [ conditions ] GROUP BY column1, column2 ORDER BY column1, column2;
  • 20. Group By Clause Consider the CUSTOMERS table having the following records: Example 1
  • 21. Group By Clause If you want to know the total amount of the salary on each customer, then the GROUP BY query would be as follows. SQL> SELECT NAME, SUM(SALARY) FROM CUSTOMERS GROUP BY NAME; This would produce the following result: Example 1(Continued)
  • 22. Group By Clause Now, let us look at a table where the CUSTOMERS table has the following records with duplicate names: Example 2
  • 23. Group By Clause Now again, if you want to know the total amount of salary on each customer, then the GROUP BY query would be as follows: SQL> SELECT NAME, SUM(SALARY) FROM CUSTOMERS GROUP BY NAME; This would produce the following result: Example 2(Continued)
  • 25. Having Clause The HAVING Clause enables you to specify conditions that filter which group results appear in the results. The WHERE clause places conditions on the selected columns, whereas the HAVING clause places conditions on groups created by the GROUP BY clause. What is Having clause? Syntax The HAVING clause must follow the GROUP BY clause in a query and must also precede the ORDER BY clause if used. The following code block has the syntax of the SELECT statement including the HAVING clause: SELECT column1, column2 FROM table1, table2 WHERE [ conditions ] GROUP BY column1, column2 HAVING [ conditions ] ORDER BY column1, column2;
  • 26. Having Clause Consider the CUSTOMERS table having the following records: Example
  • 27. Having Clause Following is an example, which would display a record for a similar age count that would be more than or equal to 2. SQL > SELECT ID, NAME, AGE, ADDRESS, SALARY FROM CUSTOMERS GROUP BY age HAVING COUNT(age) >= 2; This would produce the following result: Example(Continued)
  • 28. THANKS for watching Lecture Slide by:- Manan Pasricha Student of Bachelor of Computer Applications E-mail id: pasrichamanan81@gmail.com LinkedIn Profile:- https://www.linkedin.com/in/manan- pasricha-76029818a/