Greetings. There is something like this:
<?php foreach ($users as $user) { $sql = 'SELECT age FROM free_people WHERE user_id = ' .$user['id']. ' AND age > 0 ORDER BY photo_id DESC LIMIT 1'; $user_age = $db->select_first($sql); echo $user_age. ' лет <br>'; } In the array $ users for example 30 entries. That is, in this code there will be 30 calls to the database. I wanted to somehow do it all in one request. After all, $ user ['id'] can be combined into a string and stuffed into WHERE IN (...), but this option will output all entries by a specific id, but I need one entry, the first one sorted by photo_id (ORDER BY photo_id DESC).
"Simply put," the algorithm is as follows: take an id, select all records by it, sort it, return the first record, take a trace. id