I use SQL Server 2008 and dispose a table, that I group data on one column. For some reasons I have to use GROUP BY instead of DISTINCT (it’s a part of more complex query). Query results (only one column is returned) are fine for me.
The problem is, that I want to use this query, as a subquery in WHERE clause to filter data based on this subquery. As I see, WHERE clause sees in this subquery not only data that is displayed in query results after grouping by, but also the rest of them and this is what I do not like.
My question is, how can I use my group by query as a subquery in where clause that would see only results after grouping by?
You can use a subquery to select the required column from your existing subquery. And then pass this new subquery as input to
whereclause.