The SELF JOIN joins the table with itself.
Syntax:
SELECT column_name(s) FROM
table A, table B
WHERE condition;
Here A and B are alias for the same table.
DEMO TABLES
STUDENTS TABLE
Roll_No | Name | Marks |
1 | Dev | 35 |
2 | Ayush | 45 |
3 | Ram | 55 |
4 | Pyush | 65 |
5 | Nazim | 75 |
Example: To perform self join on the above table.
SELECT A.Roll_No AS rn, B.Marks AS m
FROM students A, students B;