I need to pull out all the entries in my database that relate to a certain user_id, order them by the time they were entered into the database (this is php unix time() seconds) and then group them by surname so that they sit with entries of the same surname.
This is the query so far.. Although it only gives me a certain amount of entries.
$sql = "SELECT * FROM people WHERE user_token='$user_token'
ORDER BY time GROUP BY surname";
What is the correct way to use ORDER and GROUP by in order to get all of the results out grouped by the surname but ordered by the time the were entered? Thanks.
The
ORDER BYclause should be the last, but you have to specify fields to be aggregated.Such as: