0 votes
in MariaDB by
What is the use of MariaDB DISTINCT clause?

1 Answer

0 votes
by

MariaDB DISTINCT Clause is used to remove duplicates from the result when it is used with a SELECT statement.

Syntax:

SELECT DISTINCT expressions      

FROM tables      

[WHERE conditions];  

Note: When you use the only expression in the DISTINCT clause, the query will return the unique values for that expression. When you use multiple expressions in the DISTINCT clause, the query will return unique combinations for the multiple expressions listed.

The DISTINCT clause doesn't ignore NULL values. So when using the DISTINCT clause in your SQL statement, your result set will include NULL as a distinct value.

Single Expression:

We have a table name "Students", having some duplicate entries. A name "Ajeet" is repeated three times.

Mariadb Distinct clause 1

Let's use the DISTINCT clause to remove duplicates from the table.

SELECT DISTINCT student_name    

FROM Students    

WHERE student_name = 'Ajeet';     

Output:

Mariadb Distinct clause 2

You can see that "Ajeet" is repeated three times in the original "Students" table but after using DISTINCT clause, it is returned one time and duplicate entries are deleted.

Related questions

0 votes
asked Jan 2 in MariaDB by john ganales
0 votes
asked Jan 5 in MariaDB by rajeshsharma
...