निहित है कि आपकी images_videos तालिका में एक आईडी फ़ील्ड है
SELECT *
FROM gallery g1
LEFT JOIN images_videos iv1
ON g1.id = iv1.gallery_id
WHERE gallery.user_id = "+another_userid+"
AND iv1.id = (SELECT Max(id)
FROM images_videos iv2
WHERE iv1.gallery_id = iv2.gallery_id)