Reputation: 13
in the below image I'm using
SELECT DISTINCT(name),date,reporting,leaving from attendance where date='2016-09-01
and I'm still getting repeating names. Why?
Upvotes: 1
Views: 39
Reputation: 12309
Actually your all rows have distinct data apart from Name column if you want only distinct names then you can get it with help of Aggregate functions, you can use MIN or MAX as per your business requirement
SELECT Name,MAX(date),MAX(reporting),MAX(leaving)
FROM attendance
WHERE date='2016-09-01'
GROUP BY Name
Upvotes: 0
Reputation: 788
When using DISCTINCT, MySQL uses all columns as grouping factor. If you want group by only one column and get all corresponding column values, use GROUP BY instead
SELECT name, date, reporting, leaving FROM attendance GROUP BY name WHERE ...
Upvotes: 1