A select statement in SQL is used to collect data from a database. The data that is pulled from the database is stored in a table-like structure, called a result-set.
Syntax:
1 |
SELECT <column name(s)> FROM <table name>
|
In the column name(s) field, you can enter single or multiple column names to select a set of columns or an asterisk (*) to select all columns from the table.
In the table name field, you must enter a single valid table name.
Note: SQL is not case sensitive. 'SELECT' is the same as 'select'.
Example:
Suppose we had a database with the following information:
| FirstName | LastName | BirthDate |
| Brian | Johnson | 1/8/1975 |
| Nick | Thomson | 3/19/1965 |
| Tyler | Jones | 12/17/1994 |
Table Name: birthdays
To select ALL of the information from the table, one would use the following query:
1 |
SELECT * FROM birthdays |
Which would yield the following results:
| FirstName | LastName | BirthDate |
| Brian | Johnson | 1/8/1975 |
| Nick | Thomson | 3/19/1965 |
| Tyler | Jones | 12/17/1994 |
To select First and Last names from the database, one would use the following query:
1 |
SELECT FirstName, LastName FROM birthdays
|
Which would yield the following results:
| FirstName | LastName |
| Brian | Johnson |
| Nick | Thomson |
| Tyler | Jones |
To select only First names from the database, one would use the following query:
1 |
SELECT FirstName FROM birthdays
|
Which would yield the following results:
| FirstName |
| Brian |
| Nick |
| Tyler |




