How to get duplicate values as single records from database with sql?
Posted On : Aug 20, 2020Last Update : Aug 20, 2020

There might be lots of duplicate values or records in databases. Any duplicate values in table columns or complete duplicate records can be listed as single (unique) values or records with DISTINCT command of SQL.
/* List all records from Shoes table. */
SELECT * FROM Shoes
/* List all different (unique) records from Shoes table. */
SELECT DISTINCT * FROM Shoes
| Shoes | ||||
|---|---|---|---|---|
| ID | Model | Color | Size | Stock |
| 1 | Adidas | White | 36 | 100 |
| 2 | Nike | White | 41 | 66 |
| 3 | Kinetix | Dark Blue | 38 | 97 |
| 4 | Puma | Black | 39 | 94 |
| 5 | New Balance | Orange | 41 | 82 |
| 6 | Puma | Red | 40 | 69 |
| 7 | Adidas | Dark Blue | 34 | 19 |
| 8 | Adidas | Red | 40 | 15 |
/* List all different Models from Shoes table. */
SELECT DISTINCT Model FROM Shoes| Shoes |
|---|
| Model |
| Adidas |
| Nike |
| Kinetix |
| Puma |
| New Balance |
/* List all different Colors from Shoes table. */
SELECT DISTINCT Color FROM Shoes| Shoes |
|---|
| Color |
| White |
| Dark Blue |
| Black |
| Orange |
| Red |
