83 Note: When you use only expression in DISTINCT clause, the query will return the unique values for that expression.When you use multiple expression in
MariaDB DISTINCT Clause
MariaDB DISTINCT Clause is used to remove duplicates from the result when we use it with SELECT statement.
Syntax:
Note: When you use only expression in DISTINCT clause, the query will return the unique values for that expression.When you use multiple expression 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.
Example:
Using Single Expression
We have a table name “Students”, having some duplicate entries. A name “Ajeet” is repeated three times.
Let’s use the DISTINCT clause to remove duplicates from the table.
Output:
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.
Using Multiple Expressions
You can use DISTINCT clause to remove duplicates from more than one expression in MariaDB.
Output:
Next TopicMariaDB From Clause