Is it better to do multiple selects from multiple tables or 1 select of all your data from all the tables?
sql, sql-server
Solution
Just write one query with joins. If you are concerned about performance there are a number of options including:
- Creating indexes that will help the performance of your selects
- Create a persisted denormalized form of the data you want so you can query one table. This would most likely be an indexed view or another table.
Problem
I have multiple tables that data can be queried from with joins. In regards to database performance: Should I run multiple selects from multiple tables for the required data? or Should I write 1 select that uses a bunch of Joins to select the required data from all the tables at once? EDIT: The where clause I will be using for the select contains Indexed fields of the tables. It sounds like because of this, it will be faster to use 1 select statement with many joins. I will however still test the performance difference between the 2. Thanks for all the great answers.