r/SQL • • Apr 25 '26

MySQL Need Help Understanding Self Joins

Exam on Tuesday, tried using AI,w2school,DBfiddle and still don't really understand self joins, i understand that it pretty much is a exact copy of the table you are using, but with all the renaming and joining portion confuses me

0 Upvotes

30 comments sorted by

View all comments

Show parent comment

1

u/squadette23 Apr 26 '26

There are just not very many concrete examples of self-join:

  • manager/subordinates is an archetypal example;
  • nested folders like in Google Docs: a folder can contain other folders;
  • referred accounts: if your website allows to refer people for signup, you can have a hierarchy of sign-ups;
  • threaded comments, like on Reddit: you can reply directly to the post, or to another comment;

If you know any others share.

2

u/read_at_own_risk Apr 26 '26

Besides recursive relationships including trees, which you already described:

  • Finding duplicate records, e.g. when cleaning up messy data.
  • Finding the record with the lowest/highest ordering/date in a group
  • Comparing members of the same or similar groups, to find differences or missing entries

2

u/r3pr0b8 GROUP_CONCAT is da bomb Apr 26 '26

If you know any others share.

bill of materials