bug 976: Fixing ambiguous references in SQL