Hello. There is a task to display each latest image for each club entry. I solved the problem this way, but displays the latest image from the entire database for each club entry. I understand that there is no connection by id , but I don’t know how to solve it.
select db_club. *, db_images.name as iName
from `db_club`,` db_images`
where db_club.type = '1'
and db_club.type = db_images.type
and db_images.id = (
select max (db_images.id)
from db_images, db_club
where db_images.type = db_club.type and db_images.type = '1'
)
order by db_club.id desc
Tried it like that. In this case, the output is from the right club but the first picture. And we need the latter.
select db_club. *, db_images.name as iName
from `db_club`,` db_images`
where db_club.type = '1'
and db_club.type = db_images.type
and db_images.bdid = db_club.id
group by db_images.bdid
order by db_club.id desc


group by db_images.typeinternal subquery of the first variant and remove the db_club table from there, it is not needed there - Mikebdidin images =>idin club. type is needed to define the page, it is here as add. field and does not participate in the selection of the last picture. - Slavik Okara