fix ambiguous column name error when counting the results

When you join some tables and some of them have the same column name, you get an error when counting the number of results.