IncorrectResultSizeDataAccessException: query did not return a unique result: 2
A query expected one row but found several.
query did not return a unique result 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 not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- 08P01 ERROR: bind message supplies 2 parameters, but prepared statement requires 1
- 1093 MySQL ERROR 1093 (HY000): You can't specify target table 'x' for update in FROM clause
- 1175 MySQL ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
Most viewed in Java
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 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.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 12 Oct 2026