Fixed bug in mysql select