Skip to content
Advertisement

Query Optimization in SQL in given case

These are the given tables:

Question is:

Write a optimized query to find out the name of all the customerIDs who ordered coffee that originated from ‘Costa Rica’ or ‘Indonesia’.

My attempt:

My teacher says it can be optimized more but I don’t see any way. Please Help me out.

Advertisement

Answer

Rather than these nested in subqueries, I would recommend exists and a correlated subquery with a join:

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