This topic is locked

subquery question

3/17/2024 3:10:52 PM
PHPRunner General questions
francesco author

when I add this subquery in Commessa table:
.....
(SELECT ROUND(SUM(orario.durata))
FROM orario
WHERE orario.commessa = commessa.commessa) AS Ore Impiegate,

it works correctly in Commessa list, but it slow down the opening of Orario list.

The subquery itself, when added to a query involving the commessa table, should not inherently affect the speed of opening or querying a different table like orario: what is the cause?
admin 3/17/2024

Modifying SQL of one table should not affect another table performance unless there two tables are related like master-details or in some other way.

In either case:

  1. Subqueires are slow, use INNER JOINs
  2. Make sure to add all relevant indexes