Use Result of one SQL Query in Another SQL Query
How can I have the result of one query be a parameter in a second query. The screenshot shows what I am attempting to do. In the first I get the software id of a particular piece of software and then that software id is used to generate a list of computers that have it installed. The software versions get updated fairly regularly and this would automate the list, without hardcoding in something that has to be changed regularly.
Community Chosen Answer
Please log in to answer
You use a sub select statement:
SELECT column1, column2, column3 from table
WHERE column4 = (select column5 from another table)
That's a very simple example, obviously. The sub select statement needs to return just one value in this instance, so the query should just return the SC.ID. If you need the outer statement to match multiple values, then you need to craft the sub select statement to return a comma separated list using GROUP_CONCAT and group the results. Your where statement would then become column4 in (select group_concat(column5) from table group by column6).
Answered 03/19/2018 by: chucksteel