Inner Join Example:
SELECT s.student_id, s.name, SUM(b.price)
FROM students s INNER JOIN books b
ON s.student_id = b.student_id
GROUP BY b.price ;
Students table:
STUDENT_ID | NAME | YEAR |
---|---|---|
1 | STUDENT_1 | I |
2 | STUDENT_2 | II |
3 | STUDENT_3 | III |
4 | STUDENT_4 | IV |
Books table:
BOOK_ID | STUDENT_ID | PRICE |
---|---|---|
1 | 1 | 40 |
2 | 2 | 50 |
3 | 3 | 70 |
4 | 1 | 100 |
5 | 2 | 120 |
6 | 4 | 90 |
7 | 3 | 200 |
8 | 2 | 150 |
Inner Join Result:
STUDENT_ID | NAME | PRICE |
---|---|---|
1 | STUDENT_1 | 140 |
2 | STUDENT_2 | 320 |
3 | STUDENT_3 | 270 |
4 | STUDENT_4 | 90 |