mysql disinct code example

Example 1: MySQL DISTINCT

When querying data from a table, you may get duplicate rows. In order to remove these duplicate rows, you use the DISTINCT clause in the SELECT statement.

Here is the syntax of the DISTINCT clause:

SELECT DISTINCT
    select_list
FROM
    table_name;

Example 2: how to find the top 2 unique records using mysql

mysql> insert into DemoTable1383 values(200,78);
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable1383 values(200,89);
Query OK, 1 row affected (0.12 sec)
mysql> insert into DemoTable1383 values(200,89);
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable1383 values(200,87);
Query OK, 1 row affected (0.29 sec)
mysql> insert into DemoTable1383 values(203,97);
Query OK, 1 row affected (0.20 sec)
mysql> insert into DemoTable1383 values(200,57);
Query OK, 1 row affected (0.17 sec)
insert into DemoTable1383 values(240,20);

Tags:

Sql Example