No need to buy the tickets in advanced. There are ticket machines at the train stations for the local trains from CGN to the city. For your trip from Cologne to Düsseldorf you can either take a local train (takes long) or a long distance train (IC, EC or ICE). I would take the long distance train and get ticket from the ticket machine or the internet. To look up the schedule and buy a ticket get on
www.bahn.de.