This is the workflow I was working after...
Get data between time and time -> sort by newest -> filter out the duplicates phonenumbers -> search for three different variables string -> print result using php.
First I used this, however it didn't sort by latest record:
SELECT id, phone, text
FROM phones
WHERE timestamp BETWEEN '2016-10-01 00:00:00' AND '2016-10-06 23:59:00'
GROUP BY user
ORDER BY timestamp DESC
After searching and testing I got it to work with a subquery:
SELECT id, phone, text
FROM phones WHERE timestamp IN(SELECT
max(timestamp)
FROM phones
GROUP BY phone )
ORDER BY timestamp DESC
However now I'm not sure where I shall put the function:
BETWEEN '2016-10-01 00:00:00' AND '2016-10-06 23:59:00'
I tried in the subquery and outside in the main. Is it possible to do this?