;WITH cte_query_1
AS
(
SELECT *
FROM database.table1
),
cte_query_2
AS
(
SELECT *
FROM database.table2
)
SELECT *
FROM cte_query_1
WHERE cte_query_one.fk IN
(
SELECT PK
FROM cte_query_2
)
With common table expressions, it is possible to create multiple queries using comma-separated AS statements. A query can then reference any or all of those queries in many different ways, even joining them.