Search for train connection at Slovakrail.sk.
You can get international train tickets at RailEurope.
From Warsaw to Bratislava there is an express train running 2 times a day (615 km, 7 – 9 hours), from Krakow 1 time a day (410 km, 7 hours 41 minutes). Express trains from Poland to Slovakia run through the Czech Republic. There is only one passenger train you can take between Poland and Slovakia, in Kysuce (Zwardoň – Žilina). Passenger transport on other rail tracks is currently suspended.
Trains between Vienna (Wien Hbf) and Bratislava (Bratislava Main Station and Bratislava Petržalka) are running 2 times an hour (70 km, 1 hour).
Once a day you can get to Bratislava by a direct train from Moscow (40 hours) and from Kiev (28 hours).