Fixed database query problem

Fixed database query problem