Clauses
Clauses
Types Of Clauses:
Where Clause
Where clause is used to specify conditions on rows so that records
get displayed as per requirement. It is used to restrict the number of
records retrieved by the table. Where clause used with select,
update, delete statements, aggregate functions and logical
operators, etc.
Syntax:
select column_name
from table_name
where condition;
Fundamentals Of SQL
Examples:
1. select *
from Student
where DeptID = 102;
Output:
StudentID Name DeptID Marks Age
2 Bob 102 34 20
6 Alex 102 78 20
Examples:
1. select DeptID, count(*)
from Student
group by DeptID;
Fundamentals Of SQL
DeptID Count(*)
Output: 101 1
102 2
103 1
104 2
105 1
Order By
Order By Clause is used for sorting the query output in either
ascending or descending order. By default, the data gets sorted in
ascending order or by using the keyword ASC. The data gets sorted in
descending order by using the keyword DESC.
Syntax:
select column_name,…
from table_name
where condition
order by column_name,… asc/desc;
Fundamentals Of SQL
Examples:
1. select * OR select *
from Student from Student
order by Name; order by Name asc;
2. select *
from Student
order by Name desc;
Fundamentals Of SQL
Having
Having clause is applied to the query output with group by clause. It
is used to limit the query output returned by group by clause. It is
similar to where clause.
Syntax:
select column_name,..
from table_name
where condition
group by column_name,…
having condition;
Examples:
1. select DeptID, count(*)
from Student
where DeptID
having count(*) > 1;
Fundamentals Of SQL