
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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)
- Related Articles
- Display distinct dates in MySQL from a column with date records
- MySQL GROUP BY and CONCAT() to display distinct first and last name
- Select distinct values from three columns and display in a single column with MySQL
- MySQL query to display columns name first name, last name as full name in a single column?
- Select distinct names from two columns in MySQL and display the result in a single column
- MySQL query to count occurrences of distinct values and display the result in a new column?
- MySQL query to display the count of distinct records from a column with duplicate records
- How to count the distinct column in MySQL?
- Display records by first fixing the first two values in a column and then using DISTINCT to display other values in MySQL
- Rename column name in MySQL?
- Update a table in MySQL and display only the initials name in a new column
- MySQL select distinct dates from datetime column in a table?
- Wildcards in column name for MySQL?
- Display duplicate record as a distinct value with corresponding values as distinct comma separated list in MySQL?
- Display MySQL Database, Table, and Column Information

Advertisements