fix bug in sql