The SQL SELECT DISTINCT Statement
The SELECT DISTINCT statement is used to return only distinct (different) values
Example
Table: Orders+----+-----------+--------+------------+| Id | Customer | Item | OrderDate |+----+-----------+--------+------------+| 1 | Raj Kumar | Press | 2021-03-10 || 2 | Ram | T-Shirt| 2021-03-10 || 3 | Raj Kumar | Press | 2021-03-10 || 4 | Ram | Press | 2021-03-10 || 5 | Raj Kumar | T-Shirt| 2021-03-10 |+----+-----------+--------+------------+
Approach
Mysql : select distinct based on multiple fields
SELECT distinct customer,items,order_date FROM orders;
Result
+-----------+--------+------------+| Customer | Item | OrderDate |+-----------+--------+------------+| Raj Kumar | Press | 2021-03-10 || Ram | T-Shirt| 2021-03-10 || Ram | Press | 2021-03-10 || Raj Kumar | T-Shirt| 2021-03-10 |+-----------+--------+------------+
Mysql : select distinct based on Customer field
SELECT distinct customer FROM orders;
Result
+-----------+| Customer |+-----------+| Raj Kumar || Ram |+-----------+
No comments:
Post a Comment