set sql_mode=''; select media.pathfile, thumbs.pathfile as tpathfile from media_relation left join media on media.id = media_relation.media_id left join thumbs on thumbs.media_id = media.id where media_relation.content_id='2522' and media_relation.prev_type='2' and media_relation.content_type='1' and thumbs.template_id='7'