Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Get several group by results from one query result

$
0
0

Is it possible to to retrieve several group by results from one query?

Currently I've a freetext book-title search system which returns the top X rows:

First it queries the book-titles SELECT TOP 16 grouped_location, grouped_author, book_title FROM books WHERE book_title like '%foo%'

then it queries the location group SELECT grouped_location, COUNT(*) FROM books WHERE book_title like '%foo%' GROUP BY grouped_location

then it queries the author group: ....

Is it possible to retrieve this information with one search? I have no problem by sending multiple command to the SQL server, but the goal is that the SQL server only performs one search and not using up all resources by searching three times.

Please keep in mind that a client-side solution, by returning all records to the client and calculate the grouped results, is not an option. It requires to only return the TOP X records due to performance reasons.


Pikard


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>