Basic Queries  «Prev  Next»

Lesson 2 SQL SELECT statement
Objective Write SELECT statements to retrieve rows

SQL SELECT Statement

Write SELECT statements that retrieve all rows from a single table. The SELECT statement is a basic element of SQL. It is used to specify the data you want to retrieve from a specified database table or tables. In it's most simple form, the SELECT statement will request the data in a single table. 

SQL Syntax

Like all languages, SQL has a required syntax .
The following Tool Tip describes a simple SELECT statement's syntax:
The SELECT statement begins the query definition
  1. The SELECT statement begins the query definition
  2. The arguments specify the columns of data to retrieve.
  3. FROM specifies the table.
  4. The table is the table name.
Select Statement Syntax

SQL keywords, such as SELECT, can be upper, lower, or mixed case. However, the convention is to use all upper case. One or more column names can be specified in a SELECT statement. If more than one name is specified, each must be separated by a comma. When the columns are later displayed, they will be displayed in the order they are specified in the argument list. The following SQL statement returns three fields from the BookTable. 

SELECT ItemNo, Title, Author FROM BookTable

View the following image to see the results of this query. 
SQL Result Set consisting of 1) ItemNo 2) Title 3) Author
SQL Result Set consisting of 1) ItemNo 2) Title 3) Author

If you want to get all the columns from a table, you do not have to specify all the column names in the argument list. You can use the asterisk ( * ) instead.
The asterisk is like a wildcard character that means everything. For example:
SELECT * FROM BookTable

In the next lesson, you will learn how to use the WHERE clause to select specific rows from a database.

Select Statement - Exercise

Click the Exercise link below to practice writing a SELECT statement. 
Select Statement - Exercise