Fixed syntax of sql query