Resolves several issues with '_id' columns being ambiguous.
This is almost exactly the Pull Request #33 from SimonHarrison, but
slightly tweaked.