Sometimes, we need to join same table twice in a query. The examples about this issue is at below.
TO DOWNLOAD THE SAMPLE LİBRARY DATABASE CLICK
Example1 : List the students who have the same date of birth.
1 2 3 4 5 6 |
Select s1.name,s1.surname,s1.birthdate,s2.name,s2.surname,s2.birthdate from students as s1,students as s2 where s1.birthdate = s2.birthdate and s1.studentId != s2.studentId and s1.studentId<s2.studentId --for not list twice order by s1.birthdate |
Result:
Example2 : List the books what have the same page counts.
1 2 3 4 5 6 |
Select b1.name,b1.pagecount,b2.name,b2.pagecount from books as b1,books as b2 where b1.pagecount = b2.pagecount and b1.bookId != b2.bookId and b1.bookId < b2.bookId order by b1.pagecount |
Result: