Reducing complexity in Mysql