Application executes complex SQL query
My application needs to execute a rather complex series of database queries. I usually just dump everything into a stored procedure and execute it that way.
But I don't have access to the database I am trying to access, so I cannot create the stored procedure. Is there a better way to do this rather than hitting the database 5-6 times to get the results I want? I could combine everything into one query, but I would like to avoid this if possible, since I would need to combine about 10 tables.
There is nothing wrong with joining 10 tables if that is ultimately what you need to do. In general, SQL is good at this. However, if there is no such connection between your 5-6 requests, run them separately.
If you choose to split the query, hitting DB 5-6 times is fine - absolutely nothing wrong with that. Your accessor (e.g. ADO.NET) probably gives you connection pooling anyway, so the overhead of multiple requests is very small.
source to share