What is SQL Clause?

SQL Clause:

In SQL, a clause is an in-built function. SQL Clause helps us filter and analyze data quickly. Clause receives a conditional expression that can be a column name involving columns that support the MySQL functions to calculate the result values for a table in the database.

Types of SQL Clause:

There are five types of SQL Clause and these are:

    i. WHERE Clause
    ii. ORDER BY Clause
    iii. GROUP BY Clause
    iv. HAVING Clause
    v. TOP Clause

WHERE Clause:

We want to see only a certain number of rows that contain specific values. For this, we would need to place the WHERE clause along with the SELECT statement. It has the following syntax:

ORDER BY Clause:

In general, the rows displayed from a query don’t have any specific order either in order of ascending or descending. But if you want them to be shown in ascending or descending order in a particular field, then you can control this order even for the selected rows. This is done by adding the clause ORDER B to the SELECT command. It has the following syntax:

GROUP BY Clause:

The GROUP BY Clause allows the formation of groups based on some given conditions. The Group By clause is used with aggregate functions. It has the following syntax:

HAVING Clause:

The HAVING clause defines criteria used to eliminate certain groups from the output, just as the WHERE clause does for individual rows. It has the following syntax:

TOP Clause:

The TOP clause is used to define the number of record rows to be shown in the result. It has the following syntax: