SQL Select Statement


The SELECT statement is used to select data from a database.

The 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

An SQL Select Example
Assume the table Persons is given as follows:

P_Id LastName FirstName Address City
1 Hansen Ola Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes
3 Pettersen Kari Storgt 20 Stavanger

To select the columns named LastName and FirstName, use a select statement like this:

 SELECT  LastName, FirstName  FROM  Persons;

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

Select * Example
Now we want to select all the columns from the Persons table. We use the following select statement:

 SELECT  *  FROM  Persons;

 P_ID        LASTNAME         FIRSTNAME         ADDRESS          CITY
 --------    -------------    --------------    -------------    -----------
 1           Hansen           Ola               Timoteivn 10     Sandnes
 2           Svendson         Tove              Borgvn 23        Sandnes
 3           Pettersen        Kari              Storgt 20        Stavanger




Demonstration
Below is an SQL test area from W3Schools, which uses the well-known Northwind sample database. The tables here are for read only because of the problem of embedding the scripts. For a fully working example, check this by using Chrome.

SQL Statement:

Edit the SQL statement and click     to see the result, or  

Result:
The Database includes:
The Database includes:

TablenameRecord
Customers91
Categories8
Employees10
OrderDetails518
Orders196
Products77
Shippers3
Suppliers29




      Alright guys, we all need to dig deep for the second half of the game.    
      Go out there and give a hundred and ten percent and bring home a win!