MySQL Select distinct
You can use the DISTINCT keyword to remove duplicate records from a field in a query.
SELECT DISTINCT (column) FROM tb_name
Suppose the user table has the following record:
SELECT DISTINCT (username) FROM user
The results are as follows:
Using the DISTINCT keyword to remove duplicate records has a large limitation. DISTINCT () can only contain one field and the query results will only return the field instead of the full data record (as in the example above).
You can try the following syntax:
SELECT DISTINCT (column), column1, column2, ... FROM tb_name
The query returns all the columns listed, but the query often invalidates the column's uniqueness, and column 1, column 2, ... can not precede DISTINCT (column).
The above example would return the following result :