Database Reference
In-Depth Information
▼
Analysis
SELECT DISTINCT vend_id
tells MariaDB to return only distinct (unique)
vend_id
rows, and so only four rows are returned, as seen in the following
output. If used, the
DISTINCT
keyword must be placed directly in front of the
column names.
▼
Output
+---------+
| vend_id |
+---------+
| 1001 |
| 1002 |
| 1003 |
| 1005 |
+---------+
Caution
Can't Be Partially
DISTINCT
The
DISTINCT
keyword applies to all columns, not
just the one it precedes. If you were to specify
SELECT DISTINCT vend_id,
prod_price
, all rows would be retrieved unless
both
of the specified columns were
distinct.
SELECT
statements return all matched rows, possibly every row in the specified
table. To return just the first row or rows, use the
LIMIT
clause. Here is an
example:
▼
Input
SELECT prod_name
FROM products
LIMIT 5;
▼
Analysis
The previous statement uses the
SELECT
statement to retrieve a single column.
LIMIT 5
instructs MariaDB to return no more than five rows. The output
from this statement is shown in the following:
▼
Output
+----------------+
| prod_name |
+----------------+