Changes

Retrieving Data From a MySQL Database

1,349 bytes added, 19:05, 9 October 2007
Restricting Number of Results
SELECT * FROM product LIMIT 10, 15;
</pre>
 
== Eliminating Duplicate Values from Results ==
 
It is not unusual for a column value combination to be duplicated throughout multiple rows. This means that when retrieving data, and particularly when retrieving data for a single column in a table, that duplicated values may appear in the results. For example:
 
<pre>
SELECT prod_desc FROM product;
+-------------------+
| prod_desc |
+-------------------+
| CD Writer |
| SATA Disk Drive |
| Cordless Mouse |
| SATA Disk Drive |
| Ergonmoc Keyboard |
| CD Writer |
+-------------------+
</pre>
 
As we can see from in the above output, our fictitious on-line store sells more than one type of disk drive and CD writer. Whilst the product codes and names are likely to be unique, the descriptions have duplications. If we wanted to get a list of product descriptions devoid of duplications we would use the ''DISTINCT'' keyword:
 
<pre>
SELECT DISTINCT prod_desc FROM product;
</pre>
 
This would result in the following output:
 
<pre>
+-------------------+
| prod_desc |
+-------------------+
| CD Writer |
| SATA Disk Drive |
| Cordless Mouse |
| Ergonmoc Keyboard |
+-------------------+
</pre>
 
Now that we have covered the basics of retrieving data using the ''SELECT'' statement, the next task is to look at [[Sorting Retrieved MySQL Data]].