Nutritics interview question

Optimize a query in php