SQL Certification - SPLessons

SQL Certification Clauses

Home > Lesson > Chapter 9
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

SQL Certification Clauses

Clause

shape Clause

Clause is defined as a set of rules, that makes to understand the concepts of SQL command in Database. SQL Clauses are very similar to SQL clause, except some functional operations.SQL statements site was intended to help software engineers and IT experts, yet new to SQL to take in the dialect and utilize it in their ordinary work. Our instructional exercise demonstrates to put into practice different SQL conditions, SQL orders, SQL proclamations and SQL administrators.

Where Clause

shape Description

To specify conditions in SQL command use where clause i.e., Select * from the table name will show all the rows from the table and Where clause will specify the condition for the result set in the table.

shape Syntax

Select * from <table_name> where <condition> ;
table_name => Any accurate table. condition => condition is a logic to get a specific record.

shape Examples

By viewing the below example, the concept of where clause can be easily understood. [sql]sql> select * from employee21; +--------+-------+-------+ | emp_id | ename | sal | +--------+-------+-------+ | 1001 | mike | 12000 | | 1002 | rambo | 13000 | +--------+-------+-------+ 2 rows in set (0.00 sec) sql> select * from employee21 where ename='rambo'; +--------+-------+-------+ | emp_id | ename | sal | +--------+-------+-------+ | 1002 | rambo | 13000 | +--------+-------+-------+ 1 row in set (0.00 sec) [/sql] The above example tells that, when where clause operation is performed on a column name like rambo, then it automatically displays the entire details of rambo like emp_id and salary.

Order by Clause

shape Description

To arrange data of a table either in ascending order or descending order based on single column use order by clause i.e., Select * from the table name will show all the rows from the table and order by clause is used to arrange the specific column in ascending or descending order.

shape Syntax

Select * from <table_name> ORDER BY <column_name> DESC;
table_name => Any accurate table. column_name => The condition that one can perform on a column by using Order by clause.

shape Examples

By viewing the below example, the concept of Order by clause can be easily understand. [sql]sql> select * from employee21; +--------+-------+-------+ | emp_id | ename | sal | +--------+-------+-------+ | 1001 | mike | 12000 | | 1002 | rambo | 13000 | +--------+-------+-------+ 2 rows in set (0.00 sec) sql> select * from employee21 order by sal desc; +--------+-------+-------+ | emp_id | ename | sal | +--------+-------+-------+ | 1002 | rambo | 13000 | | 1001 | mike | 12000 | +--------+-------+-------+ 2 rows in set (0.06 sec)[/sql] The above example tells that, when order by clause operation is performed on a column name like salary, then it automatically displays the entire details of employees in descending order.

Groupby Clause

shape Description

To divide the data of a table into groups based on single column use group by clause.

shape Syntax

Select <column_name>,Group <function1>,Group <function2> from <table_name> Group by <column_name>
table_name => Any accurate table. column_name => The condition that one can perform on a column by using Group by clause.

shape Examples

By viewing the below example, the concept of group by clause can be easily understand. [sql]sql> select * from employee21; +--------+-------+-------+--------+ | emp_id | ename | sal | deptno | +--------+-------+-------+--------+ | 1001 | mike | 12000 | 10 | | 1002 | rambo | 13000 | 20 | | 1003 | kate | 14000 | 10 | | 1003 | jeo | 14000 | 20 | | 1003 | finn | 14000 | 30 | +--------+-------+-------+--------+ 5 rows in set (0.00 sec) sql> select deptno,max(sal) from employee21 group by deptno; +--------+----------+ | deptno | max(sal) | +--------+----------+ | 10 | 14000 | | 20 | 14000 | | 30 | 14000 | +--------+----------+ 3 rows in set (0.00 sec)[/sql] The above example tells that, when group by clause operation is performed on a column name like deptno and salary, then it automatically displays the entire details of employees based on maximum salary of employee.

Having Clause

shape Description

To specify a condition with group by clause use having clause.

shape Syntax

Select <column_name>,group <function1>,group <function2> from <table_name> group by column name having <condition>;
table_name => Any accurate table. condition =>condition is a logic to get a specific record.

shape Examples

By viewing the below example, the concept of having clause can be easily understood. [sql]sql> select * from employee21; +--------+-------+-------+--------+ | emp_id | ename | sal | deptno | +--------+-------+-------+--------+ | 1001 | mike | 12000 | 10 | | 1002 | rambo | 13000 | 20 | | 1003 | kate | 14000 | 10 | | 1003 | jeo | 14000 | 20 | | 1003 | finn | 14000 | 30 | +--------+-------+-------+--------+ 5 rows in set (0.00 sec) sql> select deptno,max(sal) from employee21 group by deptno having max(sal)>13000; +--------+----------+ | deptno | max(sal) | +--------+----------+ | 10 | 14000 | | 20 | 14000 | | 30 | 14000 | +--------+----------+ 3 rows in set (0.00 sec)[/sql] The above example tells that, when having clause operation is performed on a column name like deptno and salary having salary greater that 13000, then it automatically displays the details of employees based on maximum salary.

Distinct Clause

shape Description

To eliminate duplicate values in a column use distinct clause.

shape Syntax

Select DISTINCT <column_ name> from <table_name>;
Table_name => Any accurate table. column_name => The condition that one can perform on a column by using distinct clause.

shape Examples

By viewing the below example, the concept of distinct clause can be easily understood. [sql]sql> select * from employee21; +--------+-------+-------+--------+ | emp_id | ename | sal | deptno | +--------+-------+-------+--------+ | 1001 | mike | 12000 | 10 | | 1002 | rambo | 13000 | 20 | | 1003 | kate | 14000 | 10 | | 1003 | jeo | 14000 | 20 | | 1003 | finn | 14000 | 30 | +--------+-------+-------+--------+ 5 rows in set (0.00 sec) sql> select distinct deptno from employee21; +--------+ | deptno | +--------+ | 10 | | 20 | | 30 | +--------+ 3 rows in set (0.00 sec)[/sql] The above example tells that, when distinct clause operation is performed on a column deptno, then it displays the values of jeo, finn, and kate as they have the maximum salary and automatically remove duplicate values of mike and rambo as they having minimum salary. 

Summary

shape Key Points

  • Clause - Set of rule, that make one to understand the concepts of SQL commands in the Database.
  • Where clause - Is used to specify condition in select statement.
  • Order by clause - Is utilized to arrange the table column in ascending or descending order.
  • Group by clause - Is used to divide the data of a table into groups.
  • Having clause - Is used to put condition in group by clause.
  • Distant clause - Is used to eliminate duplicate values.