{"record":{"id":"fa87e210978e5992","repo":"doctrine/orm","slug":"the-query-returned-multiple-rows-change-the-query","errorCode":null,"errorMessage":"The query returned multiple rows. Change the query or use a different result function like getScalarResult().","messagePattern":"The query returned multiple rows\\. Change the query or use a different result function like getScalarResult\\(\\)\\.","errorType":"exception","errorClass":"Doctrine\\ORM\\NonUniqueResultException","httpStatus":null,"severity":"error","filePath":"src/Internal/Hydration/SingleScalarHydrator.php","lineNumber":29,"sourceCode":"use function count;\nuse function key;\n\n/**\n * Hydrator that hydrates a single scalar value from the result set.\n */\nclass SingleScalarHydrator extends AbstractHydrator\n{\n    protected function hydrateAllData(): mixed\n    {\n        $data    = $this->statement()->fetchAllAssociative();\n        $numRows = count($data);\n\n        if ($numRows === 0) {\n            throw new NoResultException();\n        }\n\n        if ($numRows > 1) {\n            throw new NonUniqueResultException('The query returned multiple rows. Change the query or use a different result function like getScalarResult().');\n        }\n\n        $result = $this->gatherScalarRowData($data[key($data)]);\n\n        if (count($result) > 1) {\n            throw new NonUniqueResultException('The query returned a row containing multiple columns. Change the query or use a different result function like getScalarResult().');\n        }\n\n        return array_shift($result);\n    }\n}\n","sourceCodeStart":11,"sourceCodeEnd":41,"githubUrl":"https://github.com/doctrine/orm/blob/d9b9ff73016bf598ae07515f97289ce8074e97a5/src/Internal/Hydration/SingleScalarHydrator.php#L11-L41","documentation":"Error \"The query returned multiple rows. Change the query or use a different result function like getScalarResult().\" thrown in doctrine/orm.","triggerScenarios":"Thrown at src/Internal/Hydration/SingleScalarHydrator.php:29 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"d9b9ff73016bf598ae07515f97289ce8074e97a5","analyzedAt":"2026-08-21T06:13:15.863Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}