Overview of SELECT Statement

We use the SQL SELECT statement to retrieve the data from database. The SELECT statement has SIX main components. Below is the syntax of SELECT statement.

SELECT <<column_names>>
FROM <<table_names>>
WHERE <<where predicates>>
GROUP BY <<group by predicates>>
HAVING <<having predicates>>
ORDER BY <<order by list>>

It is not mandatory to use all these clauses but SELECT and FROM clauses are mandatory. Below table shows the description of all these clauses.

Component Description
FROM Here we specify which tables or views are needed for data retrieval
WHERE Here we specify the conditions to filter the rows
GROUP BY Here we specify the how our result set should be grouped or aggregated
HAVING Here we specify the condition to filter aggregated groups
SELECT Here we specify the columns which we required in the output
ORDER BY Here we specify that how our result should be sorted

Below is the example of simple SELECT statement.


        ID       CODE TEST
---------- ---------- --------------------
         1         10 TEN
         2         20 TWENTY
         3         30 THIRTY
         4         40 FOURTY
         5         50 FIFTY

Here asterisk(*) means we are retrieving all the columns from TEST1 table. Suppose we want only row having ID 3 from TEST1 table then we need to specify WHERE clause as shown below.


        ID       CODE TEST
---------- ---------- -------------
         3         30 THIRTY

In the next tutorials,  we will see more about these clauses.

Leave a Reply