How can I loop though a column of IDs I created with in a 2nd select query with a WHERE.
Example table of ids to loop through:

Here is what I got so far:
WITH myTable
AS (
select myKey as myKey
from dbo.table
Where column2 = 'x'
GROUP BY myKey
)
SELECT *
FROM table2
WHERE table2.key = myKey
I can't loop through table2 with my column of values. How can I do it?