SQL Clauses

MySQL queries are SQL functions that help us to access a particular set of records from a database table. We can request any information or data from the database using the clauses or, let’s say, SQL statements. For example, SQL Clauses receives a conditional expression that can be a column name or valid term involving columns where this supports the MySQL functions to calculate the result values for a table in the database.

There are generally five kinds of SQL Clauses in MySQL Server. They are listed as follows:

  • WHERE Clause
  • ORDER BY clause
  • HAVING Clause
  • TOP Clause
  • GROUP BY Clause
  1. SQL WHERE Clause

    In MySQL, we use the SQL SELECT statement to select data from a table in the database. Here, the WHERE clause allows filtering certain records that exactly match a specified condition. Thus, it helps us to fetch only the necessary data from the database that satisfies the given expressional conditions. The WHERE clause is used with SELECT statement as well as with UPDATE, DELETE type statements and aggregate functions to restrict the no. of records to be retrieved by the table. We can also use logical or comparison operators such as LIKE,<,>,=, etc. with WHERE clause to fulfill certain conditions.

  2. Syntax:

    SELECT Column1,….ColumnN From Table_name WHERE [condition];

  3. SQL ORDER BY Clause

    The ORDER BY clause is used in SQL for sorting records. It is used to arrange the result set either in ascending or descending order. When we query using SELECT statement the result is not in an ordered form. Hence, the result rows can be sorted when we combine the SELECT statement with the ORDER BY clause.


    SELECT column1, …,columnN FROM TableName ORDER BY column1,…,column ASC|DESC;

  4. SQL GROUP BY Clause

    The GROUP BY clause is used to group rows that have the same values in the result set. Like if we find the names of books from the table grouped by CatID.


    SELECT Column FROM Table WHERE condition GROUP BY Column [ORDER BY Column];

  5. SQL HAVING Clause

    Actually, this clause is introduced to apply functions in the query with the WHERE clause. In SQL, the HAVING clause was added because the WHERE clause could not be applied with aggregate functions.

  6. SQL TOP Clause

    The TOP clause is used to determine the number of record rows to be shown in the result. This TOP clause is used with SELECT statement specially implemented on large tables with many records. But the clause is not supported in many database systems, like MySQL supports the LIMIT clause to select limited no. of rows and in Oracle ROWNUM is used.

    For SQL Server / MS Access Query:

    SELECT TOP no|percentageColumName(s) FROM TableName WHERE condition;

Copyright 1999- Ducat Creative, All rights reserved.

Anda bisa mendapatkan server slot online resmi dan terpercaya tentu saja di sini. Sebagai salah satu provider yang menyediakan banyak pilihan permainan.