Answer the question
In order to leave comments, you need to log in
How to build a sql query?
Good afternoon!
There is a table in the database:
How to write a query so that an array with the latest records (that is, the maximum id ) is returned, but the values in the uid column are not repeated.
At the output you need something like this:
array(2) {
[0]=>
array(2) {
["uid"]=>
string(2) "10"
["text"]=>
string(2) "айяйяй"
}
[1]=>
array(2) {
["uid"]=>
string(2) "11"
["text"]=>
string(2) "бебебе"
}
}
Answer the question
In order to leave comments, you need to log in
Choose the maximum id grouped by uid and join the table by id to this selection
select uid, text from (select uid, max(id) from `table` group by uid) tmp
join `table` on tmp.uid = table.uid
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question