Mapping is your best friend and will be noticeably faster than Query of Query for this use case.
<!--- make up some data --->
<cfset departments = queryNew(
"ID , Name , Staff",
"INTEGER, VARCHAR, INTEGER",
[
{ ID: 12, Name: "Department A", Staff: 20 },
{ ID: 14, Name: "Department B", Staff: 22 },
{ ID: 33, Name: "Department C", Staff: 17 }
]
)>
<!--- map primary key from result set --->
<cfset departmentsMap = {}>
<cfloop query="departments">
<cfset departmentsMap[departments.ID] = departments.currentRow>
</cfloop>
<!--- let's pick some random departments --->
<cfset depToPick = [ 33, 12, 77, 14 ]>
<cfloop array="#depToPick#" index="depID">
<!--- skip departments that are not in the result set --->
<cfif not structKeyExists(departmentsMap, depID)>
<cfcontinue>
</cfif>
<!---
fetch fields to display using the query's [column][row] accessor,
departmentsMap[depID] returns the row index that corresponds to the the mapped primary key
--->
<cfset depName = departments["Name"][departmentsMap[depID]]>
<cfset depStaff = departments["Staff"][departmentsMap[depID]]>
<cfoutput>#depName# (ID: #depID#) has a total of #depStaff# staff members.<br></cfoutput>
</cfloop>