I created a complex search query in SQL 2008 that returns data sorted by groups, and the query itself has paging and sorting functions in it, but instead of returning a given number of records based on the parameters of the search call, it needs to return a given number of groups (so the number of entries will be different).
I am currently doing this using Temp tables (the first temp table creates a list of groups to be selected as part of the search, and then their numbers ... and the second query joins this table with the actual search ... so that it ends execution search query twice).
I am looking for a more efficient way to do this using some of the new features in SQL 2008 (which do not require the use of temporary tables).
If I can get the data in this format, I would set ...
Record Group GroupSequence
------- | --------- | --------------
1 Chickens 1
2 Chickens 1
3 cows 2
4 horses 3
5 horses 3
6 horses 3
Any ideas on how to accomplish this with a single query in SQL 2008, without using temporary tables?
sql tsql sql-server-2008 grouping
Jacob
source share