Geek University

SQL SELECT statement

The SQL SELECT statement is used to retrieve information from one or more tables. To use SELECT to retrieve table data you must, at a minimum, specify two pieces of information—what you want to select, and from where you want to select it.

The syntax of the SELECT statement is:

SELECT column_name1,column_name2 FROM table_name;

or

SELECT * FROM table_name;

Here is an example. We will use the Customer table to illustrate the SQL Select Statement:

+----+------------+-------------------+---------+-------+-------+
| id | name       | address           | city    | state | zip   |
+----+------------+-------------------+---------+-------+-------+
|  1 | Bill Smith | 123 Main Street   | Hope    | CA    | 98765 |
|  2 | Mary Smith | 123 Dorian Street | Harmony | AZ    | 98765 |
|  3 | Bob Smith  | 123 Laugh Street  | Humor   | CA    | 98765 |
+----+------------+-------------------+---------+-------+-------+

We’ll start with a simple SQL SELECT statement:

SELECT ID, NAME, ADDRESS FROM CUSTOMER;

This would produce the following result:

+----+------------+-------------------+
| ID | NAME       | ADDRESS           |
+----+------------+-------------------+
|  1 | Bill Smith | 123 Main Street   |
|  2 | Mary Smith | 123 Dorian Street |
|  3 | Bob Smith  | 123 Laugh Street  |
+----+------------+-------------------+

If you want to select all the columns of  the Customer table, you can use the following query:

SELECT * FROM CUSTOMER;

This would produce the following result:

+----+------------+-------------------+---------+-------+-------+
| id | name       | address           | city    | state | zip   |
+----+------------+-------------------+---------+-------+-------+
|  1 | Bill Smith | 123 Main Street   | Hope    | CA    | 98765 |
|  2 | Mary Smith | 123 Dorian Street | Harmony | AZ    | 98765 |
|  3 | Bob Smith  | 123 Laugh Street  | Humor   | CA    | 98765 |
+----+------------+-------------------+---------+-------+-------+

Subscribe to our Newsletter

Like us on Facebook

Share on Twitter

top
Developed by Signum Soft