Reputation: 1495
I need to extract some data from my database, but the problem is that Im getting repeated values from the database, which I do not want.
The username is stored into the database multiple times.
I tried using DISTINCT but it did not work.
Can anyone tell me how to extract the username from the database only once?
Code:
PreparedStatement preparedStatement = connect
.prepareStatement("SELECT DISTINCT username, score, name from score order by score desc limit 10");
Upvotes: 1
Views: 498
Reputation: 1269553
Use group by
instead of distinct
. Select distinct
applies to all columns being selected:
SELECT username, max(score) as score, max(name) as name
from score
group by username
order by score desc
limit 10;
Upvotes: 3