Show TOC

SELECT StatementLocate this document in the navigation structure

Use

A SELECT statement allows retrieving data from the database. Technically, it is a query with an optional clause for ordering the results. The query is either a query specification or a union of query specifications. The result of a SELECT statement is a result set .

               <select statement> ::= <query> ( <order by clause> )?.
        
<query>  ::= <query specification>
                    | <query expression>

            
Sample Code
                  SELECT * FROM employees
               

A Simple SELECT Statement. This SELECT statement selects all columns from the table employees .

Sample Code
                  SELECT empid AS employee_id, last_name,salary 
                         FROM employees 
                         WHERE salary>5000 
                         ORDER BY employee_id

               

A SELECT Statement . This SELECT statement selects data from the columns empid , last_name and salary from the table employees . The statement selects only the employees whose salary is greater than 5,000. In the result table, the data from the empid column is presented in a column named EMPLOYEE _ID , and the table is sorted by this column in ascending order.