Slide 11.8: The INSERT INTO statement
Slide 11.10: The SELECT statement (cont.)
Home

The SELECT Statement


The SELECT statement is used to select data from a table. The tabular result is stored in a result table (called the result-set).

The syntax on the right is for the SELECT statement:
 SELECT  column_name(s)
   FROM  table_name
Select Some Columns
To select the columns named “LastName” and “FirstName”, use a SELECT statement like this:

LastName FirstName Address City
Hansen Ola Timoteivn 10 Sandnes
Svendson Tove Borgvn 23 Sandnes
Pettersen Kari Storgt 20 Stavanger
Rasmussen   Storgt 67  

 SQL> select  LastName, FirstName  from  Persons;

 LASTNAME                         FIRSTNAME
 ---------------------------      ---------------------------
 Hansen                           Ola
 Svendson                         Tove
 Pettersen                        Kari
 Rasmussen

Select All Columns
To select all columns from the Persons table, use a * symbol instead of column names.

 SQL> select  *  from  Persons;

 LASTNAME          FIRSTNAME          ADDRESS           CITY
 --------------    ---------------    --------------    ------------
 Hansen            Ola                Timoteivn 10      Sandnes
 Svendson          Tove               Borgvn 23         Sandnes
 Pettersen         Kari               Storgt 20         Stavanger
 Rasmussen                            Storgt 67



The following is an SQL test area from w3schools.com where the Customers table may be created by the following command:
   SQL> create table  Customers (
     2    CustomerID   varchar(16),
     3    CompanyName  varchar(32), 
     4    ContactName  varchar(32),
     5    Address      varchar(64),
     6    City         varchar(32), 
     7    PostalCode   varchar(16), 
     8    Country      varchar(32) );
Note that the Customers table is for read only.


      SQL Execution Results