0 votes
in Sql by
What are different Clauses used in SQL?

1 Answer

0 votes
by
Clauses used in SQL

WHERE Clause: This clause is used to define the condition, extract and display only those records which fulfill the given condition.

Syntax:

SELECT column_name(s)

 FROM table_name

 WHERE condition;

GROUP BY Clause: It is used with SELECT statement to group the result of the executed query using the value specified in it. It matches the value with the column name in tables and groups the end result accordingly.

Syntax:

SELECT column_name(s)

 FROM table_name

 GROUP BY column_name;

HAVING clause: This clause is used in association with the GROUP BY clause. It is applied to each group of results or the entire result as a single group. It is much similar as WHERE clause but the only difference is you cannot use it without GROUP BY clause

Syntax:

SELECT column_name(s)

 FROM table_name

 GROUP BY column_name

 HAVING condition;

ORDER BY clause: This clause is used to define the order of the query output either in ascending (ASC) or in descending (DESC). Ascending (ASC) is set as the default one but descending (DESC) is set explicitly.

Syntax:

SELECT column_name(s)

 FROM table_name

 WHERE condition

 ORDER BY column_name ASC|DESC;

USING clause: USING clause comes in use while working with SQL JOIN. It is used to check equality based on columns when tables are joined. It can be used instead of the ON clause in JOIN.

Syntax:

SELECT column_name(s)

 FROM table_name

 JOIN table_name

 USING (column_name);

Related questions

0 votes
asked Jul 6, 2020 in Sql by Robindeniel
0 votes
asked Jun 15, 2023 in Sql by Robin
...