Comment

Comment by munch117

> If distinct is used in any of above, then question “why?” naturally arises.

Not if distinct is the default.

> Select distinct student.student_name, parent.parent_name from student join parent on student.parent_id = parent.parent_id —- silently discards rows, where by accident student/parent name combo matches several times.

Either with or without distinct can be a bug depending on what you are doing it for.

There are actually 4 variations on what you might want, and you can get all of them with distinct:

  select distinct student.student_id, student.student_name, parent.parent_id, parent.parent_name from ...
  select distinct student.student_name, parent.parent_id parent.parent_name from ...
  select distinct student.student_id, student.student_name, parent.parent_name from ...
  select distinct student.student_name, parent.parent_name from ...
parent munch117 3 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton