Fixing synapse tool query output

The original query output code could fail (if values in first entity don't exist in subsequent records) and would possible miss other columns.