Fixed SQL query issue