I'm going to guess:
select wp_ngg_gallery.name, wp_ngg_pictures.filename
from wp_ngg_gallery, wp_ngg_pictures
where wp_ngg_pictures.galleryid = wp_ngg_gallery.gid
order by wp_ngg_pictures.imagedate DESC
limit 0,1
GID, :
select wp_ngg_gallery.name, wp_ngg_pictures.filename
from wp_ngg_gallery, wp_ngg_pictures
where wp_ngg_pictures.galleryid = wp_ngg_gallery.gid
and wp_ngg_gallery.gid = $gid
order by wp_ngg_pictures.imagedate DESC
limit 0,1
($ gid , , PHP, , , , )
, wp_ngg_pictures.galleryid wp_ngg_gallery.gid, , . ( ), ( ), and wp_ngg_gallery.gid = $gid.