Fixed ambiguous SQL column name, added some tests.
Merge branch 'fix-ambiguous-column'