need to join Vertical row as per values in Horizontal rows
If I get it right

SELECT t1.`userId`, j.`job` 
FROM `table2` j
JOIN `table1` t1 ON t1.`state` IN (j.`to`, j.`from`) 
GROUP BY t1.`userId`, j.`job`
HAVING count(t1.'state') = 2