Few small sql fixes