Skip to content
Advertisement

SQL multiple SELECTs very slow to run

I have the following query (Postgres) which gives the correct results, but it is very slow. Any ideas how I can make it faster?

Result:

Schema:

Thanks, appreciate any advise.

Advertisement

Answer

I would recommend aggregation:

Note that the parentheses after DISTINCT around (vesselimo) are quite misleading. SELECT DISTINCT applies to the entire row, not just to some parenthesized expression.

If you are using an old version of Postgres, then it might not support filter. You can phrase that as:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement