Skip to content

Tag: query-performance

SQL Query Performance Enhancement on NOT IN

Suppose I have a query need to lookup users who bought book A but not bought book B. Typical SQL query can be: This not in query looks not efficient, any enhancement I can do this query? Answer Try using exists clause instead of IN clause – Apart from this you my try having index on below columns &#8211…

SQL Server Query filter with order is slow

I have been struggling with this for a while. I have a database with three tables (each of which has millions of records) as follows (removed some columns for simplicity): There exists indexes As follows To eliminate the possibility that the slowness is because of the selected columns, I only select a fixed v…