In MySQL I am trying to get the only one latest data of each user. I am cureently doing the following query
SELECT DISTINCT username, value, date
FROM table
WHERE date >= CURDATE()
ORDER BY date DESC
Its returning all the values by username and the query is to slow. Is there any way to make it faster and get only one latest value of each user?
The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:
ALTER TABLE `table` ADD INDEX `table_idx_date` (`date`);
SELECT
DISTINCT table.username,
table.value,
table.date
FROM
table
WHERE
table.date >= CURDATE()
ORDER BY
table.date DESC