What is the performance of subqueries vs two separate select queries? [closed] What is the performance of subqueries vs two separate select queries? [closed] sqlite sqlite

What is the performance of subqueries vs two separate select queries? [closed]


It depends on many factors. Two separate queries means two requests. A request has a little overhead, but this weighs more heavily if the database is on a different server. For subqueries and joins, the data needs to be combined. Small amounts can easily be combined in memory, but if the data gets bigger, then it might not fit, causing the need to swap temporary data to disk, degrading performance.

So, there is no general rule to say which one is faster. It's good to do some testing and find out about these factors. Do some tests with 'real' data, and with the amount of data you are expecting to have in a year from now.

And keep testing in the future. A query that performs well, might suddenly become slow when the environment or the amount of data changes.