more sql query fixes