i have mysql db on run query gets top row each group (according grouping criterion): select ranked.id, ranked.os, ranked.version, ranked.timestamp, agent_metadata.* (select *, @os_rank := if(@current_os = os, @os_rank + 1, 1) os_rank, @current_os := os default_version order os desc, timestamp desc ) ranked inner join agent_metadata on ranked.os = agent_metadata.os , ranked.version = agent_metadata.version os_rank = 1; when run query on db (using datagrip) expected result. however, when run same query go code using db.query , instead of getting 2 rows, 5 rows. i have logic builds query before running print log: // ... build query query := qb.string() logger.debugf("executing: %s", query) if rows, err := repository.connection.query(query); err != nil { return defaults, errors.wrap(err, "get default versions") } else { defer rows.close() rows.next() { result := defaultversionextended{} err := rows.scan(