Home » SQL

SQL Clauses

Define SQL clauses: Here, we are going to learn about where clauses, group by clauses, having clauses, order by clauses.
Submitted by Preeti Jain, on March 30, 2018

SQL Clauses

SQL clauses are the special/reserve words, which have a specific meaning in a SQL language.

Note: We should prefer to write clauses in capital letters but it is not mandatory.

1) WHERE Clause

Where clause is used to fetch a conditional record. We should implement where clause whenever condition required.

Syntax:

SELECT col1,col2 FROM tablename WHERE col1 = value;

2) GROUP BY Clause

GROUP BY clauses is used to fetch a grouping record. We should implement GROUP BY clauses whenever grouping required.

GROUP BY clauses is used to arrange similar records into groups.

Syntax:

SELECT col1,col2 FROM tablename GROUP BY columnname;

3) HAVING Clause

HAVING clauses is used to fetch a conditional record after grouping. We should implement HAVING clauses whenever condition required after grouping.

HAVING clauses works on those rows which returned by GROUP BY clauses.

Syntax:

SELECT col1,col2.....coln 
FROM tablename 
WHERE colname = value 
GROUP BY colname 
HAVING colname = value;

ORDER BY Clause

ORDER BY clauses is used to fetch sorted record. We should implement ORDER BY clauses whenever sorting required.

ORDER BY clauses is used to sort records either in ascending(ASC) or descending order(DESC) based on one or more column.

Syntax:

SELECT col1,col2.....coln 
FROM tablename 
WHERE colname = value 
GROUP BY colname 
HAVING colname = value 
ORDER BY columname (asc/desc);


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.