MySQL-Query & Code Optimize