DISTINCT clause in MariaDB

MariaDB DISTINCT The MariaDB DISTINCT clause is used with the SELECT statement to eliminate the duplicate records from the result set.

Syntax:

SELECT DISTINCT columns  
FROM tables  
WHERE conditions;  

Parameters: conditions: It is used to specify the conditions to be strictly fulfilled for the selection.

Example 1: Using Distinct Select for single column. Players table:

ID	NAME	   SPORTS
1	Sachin	   Cricket
2	Dhoni	   Cricket
3	Sunil	   Football
4	Srikanth   Badminton
5	Mary	   Boxing

Distinct Select Query:

SELECT DISTINCT sports  
FROM Players  
WHERE sports = ‘Cricket’;

Output:

SPORTS
Cricket

Explanation: The ‘Players’ is an already existing table, from which we are retrieving the unique value where SPORTS = ‘Cricket’ from the SPORTS column.

Example 2: Using Distinct Select for multiple columns. Players table:

ID	NAME	         SPORTS
1	Sachin	         Cricket
2	Dhoni	         Cricket
3	Sunil	         Football
4	Srikanth	 Badminton
5	Srikanth	 Badminton

Distinct Select Query:

SELECT DISTINCT name, sports  
FROM Players  
WHERE id > 2;

Output:

NAME	        SPORTS
Sunil	        Football
Srikanth	Badminton

Explanation: The ‘Players’ is an already existing table, from which we are retrieving the unique values from the NAME and SPORTS column where ID is greater than 2.

Please follow and like us:
Content Protection by DMCA.com