more sql query adjustments