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 diagram describes a simple SELECT statement's syntax:
SQL SELECT Statement Syntax
SELECT arguments FROM table
The SELECT statement defines the query and specifies the columns of data to get from the specified table.
The SELECT statement begins the query definition.
The arguments specify the columns of data to retrieve.
FROM specifies the table.
The table is the table name.
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.
ItemNo Title Author
A700-001 Hawaii On $10 a Day Pincher
A500-001 Using Visual InterDev 6.0 Smarts
A205-001 How To Build a Space Shuttle O'Really
A200-001 How To Fly a Space Shuttle O'Really
A505-001 UNIX Unleashed Burk & Horvath
A500-010 Active Server Pages Black Book Williams, Barber, Newkirk
A200-005 AIM/FAR 1999 Spence
A200-010 Instrument Flying Thom
A550-001 Mythical Man-Month Brooks
A540-010 Software Metrics Fenton
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.