Skip to content
Advertisement

Optimizing SELECT COUNT to EXISTS

I have a query to find certain customers from a table.

There is an index on customerid, so the DB scans all rows with customerid = 22.

Since the result is processed by checking whether the count returns zero or more than zero, how can I optimize the query? I.e. such that at the first customer row with amount <> 0 the query returns 0 else if all rows are = 0, then return 1.

Advertisement

Answer

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