предполагаше, че таблицата ви images_videos има поле за ID
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)