Jayson Tamayo Jayson Tamayo - 1 year ago 83
MySQL Question

additional column in sql results

Given the following MySQL statement:

SELECT name FROM jobtype_descriptions WHERE id IN (SELECT job_description FROM `table2` WHERE id IN (10684,10580,10583,10582,10581,10579,10576))

When executed, it gives me the following result:

enter image description here

But I want to include the ids job_description column from the inner select statement as the first column. Here's the result of the inner select statement:

enter image description here

I tried using alias of the second select statement but didn't work.

Answer Source

Modify your query to be like

SELECT t2.id, jtd.name 
FROM jobtype_descriptions jtd
JOIN table2 t2 ON jtd.id = t2.job_description
WHERE t2.id IN (10684,10580,10583,10582,10581,10579,10576);