Adding DISTINCT to make duplicates go away hides the real problem: the join is multiplying rows. The engine still builds every duplicate and then sorts or hashes them all away, so you pay for the fan-out twice.
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-08-25