COUNT DISTINCT
Syntax
COUNT(DISTINCT expr,[expr...])
Description
Returns a count of the number of different non-NULL values.
COUNT(DISTINCT) returns 0 if there were no matching rows.
Although, from MariaDB 10.2.0, COUNT can be used as a window function, COUNT DISTINCT cannot be.
Examples
CREATE TABLE student (name CHAR(10), test CHAR(10), score TINYINT); INSERT INTO student VALUES ('Chun', 'SQL', 75), ('Chun', 'Tuning', 73), ('Esben', 'SQL', 43), ('Esben', 'Tuning', 31), ('Kaolin', 'SQL', 56), ('Kaolin', 'Tuning', 88), ('Tatiana', 'SQL', 87), ('Tatiana', 'Tuning', 83); SELECT COUNT(*) FROM student; +----------+ | COUNT(*) | +----------+ | 8 | +----------+ SELECT COUNT(DISTINCT (name)) FROM student; +------------------------+ | COUNT(DISTINCT (name)) | +------------------------+ | 4 | +------------------------+
See Also
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.
© 2021 MariaDB
Licensed under the Creative Commons Attribution 3.0 Unported License and the GNU Free Documentation License.
https://mariadb.com/kb/en/count-distinct/