More sql query compatibility tweaks