Simple Queries in SQL

Queries are one of a thing that make database powerful. The “Query” refers to action of retrieving data from the database. There are following some common clauses used in SQL.

SELECT :- SELECT clause used to retrieves data from the table. SELECT command also provides the query capability this means that executing SELECT statement, information currently in the table show on the screen. Syntax:


FROM :- FROM clause present in every query. It is following by a space and there the name of the table being used as the source of the information. Syntax:

SELECT <column name> FROM <table name>;

WHERE :- WHERE clause used with the SELECT and FROM command. Suppose we select all rows of STUDENT table, but we see only certain number of rows the contain specifies values. For this, we would need to place WHERE clause along with the SELECT statement. Syntax:

SELECT <column name> FROM <table name> WHERE <column name><operator><value>;

ORDER BY :-  If we want to ascending or descending order in particular field, then we can control this order for the selected rows.This is done by adding the clause order by to SELECT command. Syntax:

SELECT <column name (s)> FROM <table name> WHERE <condition> ORDER BY <column sequence>[<ASC/DESC>];

GROUP BY :- This clause allows to from groups by used on the condition. Syntax:

SELECT <column>,function(<column>), function(<column>) FROM table GROUP BY <column>;

UPDATE :- UPDATE clause used to change or modifies data value in the table. Syntax:

UPDATE < table name> set <column=new column value>[WHERE <condition>];

DELETE :- DELETE clause used to remove row from the table with command DELETE. Syntax:

DELETE FROM <table> WHERE <condition>;

HAVING :- This clause defines criteria used to eliminate certain groups from the output just as the WHERE clause does for individual rows.

Leave a Reply