Return a list of surnames, with each surname appearing only once? : Distinct « Select Clause « SQL / MySQL






Return a list of surnames, with each surname appearing only once?

       
mysql>
mysql>
mysql> CREATE TABLE sales_rep(
    ->   employee_number INT,
    ->   surname VARCHAR(40),
    ->   first_name VARCHAR(30),
    ->   commission TINYINT
    -> );
Query OK, 0 rows affected (0.01 sec)

mysql>
mysql>
mysql> INSERT INTO sales_rep values(4,'Rive','Mongane',10);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO sales_rep values(5,'Smith','Mike',12);
Query OK, 1 row affected (0.00 sec)

mysql>
mysql>
mysql> SELECT DISTINCT surname FROM sales_rep ORDER BY surname;
+---------+
| surname |
+---------+
| Rive    |
| Smith   |
+---------+
2 rows in set (0.00 sec)

mysql>
mysql> drop table sales_rep;
Query OK, 0 rows affected (0.01 sec)

   
    
    
    
    
    
    
  








Related examples in the same category

1.Use DISTINCT to get non-dupliate records
2.Use DISTICNT to get unique value
3.Eliminating Duplicate Data Using DISTINCT 1
4.Eliminating Duplicate Data Using DISTINCT 2
5.Select distinct records using JOIN
6.The SQL key word DISTINCT has the effect that equivalent data records are output only once.
7.DISTINCT works with multiple-column output too.
8.how many different drivers there are, use COUNT(DISTINCT)
9.DISTINCT with two columns
10.DISTINCT works with expressions, not just column values.
11.Inserting name values into the multisequence table generates separate sequences for each distinct name:
12.Count distinct
13.Distinct sub string
14.Average distinct value
15.The fraction of the records that contain unique or non-unique names: