Bug fixed on query statement