fixed sql for table with indexes