Switch to: V11V10V9V8V7V6V5

Suppression of Duplicated Records

DISTINCT keyword is indicated at the beginning of the returning columns' list and serves for the suppression of duplicated records out of the query results table.

CREATE TABLE t1 ( f1 CHAR(20), f2 CHAR(20) );
INSERT INTO t1 VALUES ( 'Ivan', 'Ivanov' );
INSERT INTO t1 VALUES ( 'Ivan', 'Petrov' );
INSERT INTO t1 VALUES ( 'Ivan', 'Ivanov' );
 
SELECT DISTINCT f1, f2 FROM t1

produces:

f1 f2
Ivan Ivanov
Ivan Petrov

With the help of the given keyword you can also indicate that before statistic function applying to the field you should suppress all the duplicated records out of it. For that you should include DISTINCT keyword before the statistic function argument at once after the opening round bracket.

How many different posts are there in the company?

SELECT COUNT(DISTINCT title)
FROM salesreps	

It is allowed to use DISTINCT keyword in all statistic functions and also you can apply the expressions as the arguments for all the functions.

The given keyword can be applied only once in one query. If it is applied together with the argument of one of the statistic functions, it can be used with any other argument. If it is pointed before the returning fields' list it can be used in anyone of statistic functions. The only exception to this rule is the case when DISTINCT keyword is used inside the sub-query.