Basics of the SELECT Statement
In a relational database like the one used by Filopto, data is stored in tables. For ease of use, we have created fictional tables for our examples. To view the Filopto tables structure you can use the "System/Database Manager" which list all tables in the system. You will want to review the various tables and their contents before directly writing the SQL statements for a report. You can also review some SQL statements by looking at the ones generated in the various reports or those generated by the "Ask a Question".
An example table would relate Social Security Number, Name, and Address:
EmployeeAddressTable
SSN |
FirstName |
LastName |
Address |
City |
State |
512687458 |
Joe |
Smith |
83 First Street |
Howard |
Ohio |
758420012 |
Mary |
Scott |
842 Vine Ave |
Losantiville |
Ohio |
102254896 |
Sam |
Jones |
33 Elm St. |
Paris |
New York |
876512563 |
Sarah |
Ackerman |
440 U.S. 110 |
Upton |
Michigan |
Now, let's say you want to see the address of each employee. Use the SELECT statement, as follows:
SELECT FirstName, LastName, Address, City, State
FROM EmployeeAddressTable;
The following is the results of your query of the database:
FirstName |
LastName |
Address |
City |
State |
Joe |
Smith |
83 First Street |
Howard |
Ohio |
Mary |
Scott |
842 Vine Ave |
Losantiville |
Ohio |
Sam |
Jones |
33 Elm St. |
Paris |
New York |
Sarah |
Ackerman |
440 U.S. 110 |
Upton |
Michigan |
To explain what you just did, you asked for the all of data in the EmployeeAddressTable, and specifically, you asked for the columns titled FirstName, LastName, Address, City, and State. Note that column names and table names do not have spaces. They must be typed as one word or as they appear in the Database structure. Also, the statement ends with a semicolon ( ; ). The general form for a SELECT statement, retrieving all of the rows in the table is:
SELECT ColumnName, ColumnName, ...
FROM TableName;
To get all columns of a table without typing all column names, use:
SELECT * FROM TableName;
The " * " command means Select ALL columns.