Fix sql query in view action.