database query tweak