SQL SELECT

The SQL SELECT clause selects data from one or more database tables and/or views. In its basic form the SQL SELECT syntax looks like this:

SELECT ColumnName1, ColumnName2, FROM Table1

Let's have a look at the SELECT SQL statement above. The first part starts with the SELECT clause followed by a list of columns separated by commas. This list of columns defines which columns we are selecting data from. The second part of our SQL SELECT starts with the FROM clause followed by name of table from where we are extracting data.

We will use a table called Weather with 3 columns - City, AverageTemperature and Date, to give a real world SQL SELECT example:

CityAverageTemperatureDate
New York22 C10/10/2005
Seattle21 C10/10/2005
Washington20 C10/10/2005

To select all cities from the above table, we will use this SQL SELECT statement:

SELECT CityFROM Weather
The result will be:
City
New York
Seattle
Washington

If we want to select all the data (all columns) from the Weather table we can do it with the following SQL SELECT:

SELECT * FROM Weather

The * replaced the column list following the SELECT SQL clause, thus instructing the SQL interpreter to return all columns.