MySQL Query Creation and Performance Optimisation