fix bug in SQL