Fixed a bug where the code that generated GROUP BY SQL was not considering tables with multiple primary keys.