Self Joins - Intro to Relational Databases
0:00 - 0:04When you ran this query,
what was it that wasn't right about it?
0:04 - 0:06Well, it seems to think
that each student is his or
0:06 - 0:12her own roommate, and it lists each pair
of roommates twice in alternating order.
0:12 - 0:16There are a lot of ways to fix this,
but here's just one of them.
0:16 - 0:21By asking only for the rows where
this id, is less than that id.
0:21 - 0:25We eliminate the rows where they're
equal, in other words the same student.
0:25 - 0:28And, we eliminate one out
of each pair of duplicates.