I am querying to get three columns (A,B,S) based on the top 200 of the Sum of third column (S) of a table (this has some condition checks).
SELECT TOP 200 PlantId, SKU, SUM(Demand)
FROM NetDemandTable
WHERE DemandWKId>=62 AND DemandWKId<=76
GROUP BY PlantId, SKU
ORDER BY SUM(Demand) DESC
The resultant Column B is considered as a unique records for the other select query which is again A,B,S columns, but with different condition and the this column B should intersect with the Results obtained in select Query 1.
SELECT PlantId, SKU, SUM(Demand)
FROM CuringNetDemandCopy
WHERE DemandWKId < 62
GROUP BY PlantId, SKU
ORDER BY SUM(Demand) DESC
Now the second query results should select only the entities of SKU in Column B obtained from the first query.