revised mysql code