Fixed bug on SQL