Fixed error on db query