There is only one direct Hat Yai to Cha Am train, an overnight Rapid service which offers cheap seating in 3rd and 2nd class, as well as 2nd class fan and air-conditioned sleeper carriages.
If this train does not fit in with your travel arrangements, there are other trains you can take to get to Cha-am beach from Hat Yai.
What you do is take one of the Hat Yai to Hua Hin trains (Hua Hin is just 25 km south of Cha Am).
When you get to Hua Hin Railway Station, just walk down to the main road, turn left and you will find a local bus and minivans that run between Hua Hin and Cha Am.
Tickets on this Rapid train service cost:
3rd class fan cooled seat: Adult 230 THB - Child 170 THB
2nd class fan cooled seat: Adult 388 THB - Child 249 THB
2nd class Day and Night Sleeper carriage (fan cooled):
Upper sleeping berth: Adult 518 THB - Child 379 THB
Lower sleeping berth: Adult 588 THB - Child 449 THB
2nd class Day and Night Sleeper carriage (air-conditioned):
Upper sleeping berth: Adult 688 THB - Child 549 THB
Lower sleeping berth: Adult 758 THB - Child 619 THB
Lower berths are much more comfortable than the narrower upper berths.
If you want to travel in any other class apart from 3rd class, advance booking is highly recommended for this train trip, as these services to Bangkok, can operate full during the high season (November to April).
To book tickets in Hat Yai, you can visit the advance booking office at Hat Yai Station (on your left as you go through the main entrance).
If you want to book tickets further in advance, you can also visit any other SRT railway station in Thailand.
Or, if you don't mind paying a little bit more:
For all you need to know about the railway station in Hat Yai, click on the photo link below: