SELECT CONCAT('internal_data/attachments/', FLOOR(ad.data_id / 1000), '/', ad.data_id, '-', ad.file_hash, '.data')
FROM xf_mg_media_item AS m
LEFT JOIN xf_attachment AS a ON
(a.content_id = m.media_id AND a.content_type = 'xfmg_media')
LEFT JOIN xf_attachment_data AS ad ON
(a.data_id = ad.data_id)
WHERE m.media_id IN(999, 9999)