SQL: SELECT DISTINCT is usually a join fan-out you have not fixed

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.

Full code & output

This topic is available to PRO members.

Sign in Create a free account

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