I'm learning SQL and I came across the below-mentioned scenario.
Table 1
id Name City
1 Ryan Chennai
2 Tom Banglore
3 Sam Pune
4 Kat Mumbai
Table 2
id month salary
1 prev 1000
1 cur 4000
1 next 3000
2 prev 1000
2 cur 3000
2 next 4000
3 prev 2000
3 cur 5000
3 next 6000
4 prev 1500
4 cur 2500
4 next 3000
Output table should look like this
id name city cur prev next
1 Ryan Chennai 4000 1000 3000
2
3
4
(Similarly for other ids as well.)
So what are the different ways to achieve this and also it would be very helpful if someone helps me to understand how to approach these kinds of problems.