Removing duplicates and selecting only the unique combinations of values in the specified columns : Simple Select « Select Clause « SQL / MySQL






Removing duplicates and selecting only the unique combinations of values in the specified columns

       
mysql>
mysql>
mysql> CREATE TABLE cat_mailing
    -> (
    ->  last_name       CHAR(40) NOT NULL,
    ->  first_name      CHAR(40) NOT NULL,
    ->  street          CHAR(40) NOT NULL
    -> );
Query OK, 0 rows affected (0.01 sec)

mysql>
mysql> INSERT INTO cat_mailing (first_name, last_name, street)
    ->  VALUES
    ->          ('Jim','Isaacson','515 Fordam St., Apt. 917'),
    ->          ('Wallace','Baxter','57 3rd Ave.'),
    ->          ('Taylor','McTavish','432 River Run'),
    ->          ('Marlene','Pinter','9 Sunset Trail'),
    ->          ('WALLACE','BAXTER','57 3rd Ave.'),
    ->          ('Bartholomew','Brown','432 River Run'),
    ->          ('Marlene','Pinter','9 Sunset Trail'),
    ->          ('Wallace','Baxter','57 3rd Ave., Apt 102')
    -> ;
Query OK, 8 rows affected (0.00 sec)
Records: 8  Duplicates: 0  Warnings: 0

mysql>
mysql> SELECT * FROM cat_mailing;
+-----------+-------------+--------------------------+
| last_name | first_name  | street                   |
+-----------+-------------+--------------------------+
| Isaacson  | Jim         | 515 Fordam St., Apt. 917 |
| Baxter    | Wallace     | 57 3rd Ave.              |
| McTavish  | Taylor      | 432 River Run            |
| Pinter    | Marlene     | 9 Sunset Trail           |
| BAXTER    | WALLACE     | 57 3rd Ave.              |
| Brown     | Bartholomew | 432 River Run            |
| Pinter    | Marlene     | 9 Sunset Trail           |
| Baxter    | Wallace     | 57 3rd Ave., Apt 102     |
+-----------+-------------+--------------------------+
8 rows in set (0.00 sec)

mysql>
mysql> SELECT last_name, first_name FROM cat_mailing
    -> GROUP BY last_name, first_name;
+-----------+-------------+
| last_name | first_name  |
+-----------+-------------+
| Baxter    | Wallace     |
| Brown     | Bartholomew |
| Isaacson  | Jim         |
| McTavish  | Taylor      |
| Pinter    | Marlene     |
+-----------+-------------+
5 rows in set (0.00 sec)

mysql>
mysql> drop table cat_mailing;
Query OK, 0 rows affected (0.00 sec)

   
    
    
    
    
    
    
  








Related examples in the same category

1.Explain select command
2.Get the number, name, and date of birth of each player resident in Stratford; sort the result in alphabetical
3.Do math calculation with select
4.SELECT statement includes three select list elements
5.Select rows
6.The expression in the select list subtracts the Reserved value from the total
7.Display the names of only those authors whose surname starts with one of the letters L through Z:
8.Determines all employees whose names contain the sequence of letters er.
9.Use a wildcard (*) to return all the fields
10.Using mysql as a Calculator
11.Identifying What Values to Display
12.Using the aliases p1 and p2 to refer to the book table different ways