SELECT .. FROM:

SELECT is one of most commonly used DML(Data Manipulation Language) commands. It is used to retrieve data from the database. The general form for a SELECT statement, retrieving all of the rows in the table is:

SELECT ColumnName, ColumnName, ...
FROM TableName;

Lets us look at the following table (tbl_employee) including five fields: Social_Security , Last_Name, First_Name, Address and Zip_Code:

Social_Security Last_ Name First_Name Address Zip_Code
476-02-3475 Mitchel John 1223 West Palm Beach Rd 85023
376-76-9083 Spencer Teri 2349 S. 76th Street #102 53219
733-05-3598 James Taylor 23 N. Atlantic Blvd 76215
387-41-1189 Pewinsky Lewis 675 E Indian School Rd 85023
498-32-9089 James Sue 3567 E Tatum Blvd 85032


If you want to retrive all the information in the table,  use the following statement:

SELECT * FROM tbl_employee

The result from the command is

Social_Security Last_Name First_Name Address Zip_Code
476-02-3475 Mitchel John 1223 West Palm Beach Rd 85023
376-76-9083 Spencer Teri 2349 S. 76th Street #102 53219
733-05-3598 James Taylor 23 N. Atlantic Blvd 76215
387-41-1189 Pewinsky Lewis 675 E Indian School Rd 85023
498-32-9089 James Sue 3567 E Tatum Blvd 85032

 

If you want to limit the number of fields from the table use the following command

SELECT First_Name, Last_Name, Zip_Code 
FROM tbl_employee


The following is the results of your query of the database:

Last_Name First_Name Zip_Code
Mitchel John 85023
Spencer Teri 53219
James Taylor 76215
Pewinsky Lewis 85023
James Sue 85032

To explain what you just did, you asked for the all of data in the table tbl_employee, and specifically, you asked for the fields called First Name, Last Name, Zip Coe. Note that column names and table names do not have spaces.

Back to the homepage