Skip to content
Advertisement

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?

Advertisement

Answer

Try using exists clause instead of IN clause –

Apart from this you my try having index on below columns –

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