|
|
|
|
|
by munch117
972 days ago
|
|
> 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 ...
|
|
Sometimes I wonder if we're just weird, somehow avoiding this issue.