fixed db query