Fix the parameter ordering in derived queries