Retrieving Data From a MySQL Database

From Techotopia
Revision as of 18:36, 9 October 2007 by Neil (Talk | contribs)

Jump to: navigation, search

Just a database system would be useless without some way to write data to the database files, a database would be similarly useless if there were no way to extract the stored data. Amongst the available SQL statements, one of the most frequently used is the SELECT statement. The purpose of the SELECT statement is to retrieve data from a database table based on specified criteria. In this chapter we will cover the use of the SELECT statement in detail.

Retrieving a Single Column

The most basic of SELECT statements simply retrieves a single column of all the rows of a table. The following SQL statements select a database named extract all the product_description column entries in the product table:

USE MySampleDB;
SELECT product_description FROM product;

Once executed, this command will display a list of every product description contained in the product table:

+-------------------+
| prod_desc         |
+-------------------+
| CD Writer         |
| Cordless Mouse    |
| SATA Disk Drive   |
| Ergonomic Keyboard|
+-------------------+
4 rows in set (0.00 sec)