SELECT
xx.value_str tablename,
yy.id_job jobid
FROM
(
SELECT
a.`value_str`,
c.`name`,
CONCAT('/', o.`directory_name`) directory_name
FROM
r_step_attribute a
LEFT JOIN r_step b ON a.`id_step` = b.`id_step`
LEFT JOIN `r_transformation` c ON b.`id_transformation` = c.`id_transformation`
LEFT JOIN `r_directory` o ON c.`id_directory` = o.`id_directory`
WHERE
b.`id_step_type` IN ('205', '151')
AND a.`code` = 'table'
) xx
LEFT JOIN (
SELECT
DISTINCT k.`id_job`,
(
SELECT
j.`value_str`
FROM
`r_jobentry_attribute` j
WHERE
j.`code` = 'name'
AND k.`id_jobentry` = j.`id_jobentry`
) AS exg_name,
(
SELECT
j.`value_str`
FROM
`r_jobentry_attribute` j
WHERE
j.`code` = 'dir_path'
AND k.`id_jobentry` = j.`id_jobentry`
) AS dir_name
FROM
`r_jobentry` k
LEFT JOIN `r_jobentry_attribute` j ON k.`id_jobentry` = j.`id_jobentry`
WHERE
k.`id_jobentry_type` = '87'
AND j.`code` IN ('name', 'dir_path')
) yy ON xx.name = yy.exg_name
AND xx.directory_name = yy.dir_name