Fix sql query usage