The last car we bought only had to get us across the country and last a couple months...(long story) so we bought it right off the dealer's lot for cash the day before the movers were coming to pack up all our stuff. It was a year older than the car that got rear ended on the way home from its checkup the day before, and had 50K more miles on it, but it was a Honda in very good condition, no rust. (Honda keeps computerized records of upkeep, so we knew its maintenance history.)
Well, here it is nearly three years later, and we are still driving it. (Life intervened while we were making other plans.) So, besides luck, I'd recommend an ongoing relationship with the dealership, so you can trust their recommendations--as well as knowing the make and model repair history of any used car. Not just the individual car you might buy, but also of the model as a whole. Some makes are good some years and terrible others.
For that reason, I wouldn't buy a new car. No way to predict what its maintenance costs would be, besides which, the first year depreciation is ridiculous.