IncorrectResultSizeDataAccessException: query did not return a unique result: 2
A query expected one row but found several.
Seen on:
Java
Meaning
Spring Data repository methods returning a single entity/Optional throw when multiple rows match. The data or the query assumption is wrong.
Common causes
- Duplicate data where uniqueness was assumed
- findBy... returning single instead of List
- Missing unique constraint
⚡ Quick fix
- Return a List and handle duplicates
- Add a unique constraint
- Use findFirstBy… with ordering when you want one
Detailed fix by platform
Java
Optional<User> findFirstByEmailOrderByIdDesc(String email);
How to diagnose
- Query — Which method?
- Data — Why several rows?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026