Display distinct column name in MySQL


Let us create a table −

mysql> create table DemoTable1996
(
   ShippingDate datetime,
   CustomerName varchar(20)
);
Query OK, 0 rows affected (0.84 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable1996 values('2019-12-21 10:45:00','Chris');
Query OK, 1 row affected (0.11 sec)
mysql> insert into DemoTable1996 values('2019-12-21 12:10:00','David');
Query OK, 1 row affected (0.09 sec)
mysql> insert into DemoTable1996 values('2019-12-20 12:10:00','Bob');
Query OK, 1 row affected (0.14 sec)

Display all records from the table using select statement −

mysql> select * from DemoTable1996;

This will produce the following output −

+---------------------+--------------+
| ShippingDate        | CustomerName |
+---------------------+--------------+
| 2019-12-21 10:45:00 | Chris        |
| 2019-12-21 12:10:00 | David        |
| 2019-12-20 12:10:00 | Bob          |
+---------------------+--------------+
3 rows in set (0.00 sec)

Here is the query to display distinct column name −

mysql> select * from DemoTable1996 group by date(ShippingDate);

This will produce the following output −

+---------------------+--------------+
| ShippingDate        | CustomerName |
+---------------------+--------------+
| 2019-12-21 10:45:00 | Chris        |
| 2019-12-20 12:10:00 | Bob          |
+---------------------+--------------+
2 rows in set (0.07 sec)

Updated on: 02-Jan-2020

124 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements