Happily I haven't had to buy a car since 2020, but I had good luck using cargurus to spot cars that had sat on smaller dealer lots for awhile. I understand that some dealers take out loans of their own to cover the vehicle while it's on the lot (a "floor loan") so as the vehicle sits, their incentive to unload it increases.
Obviously that's not relevant in the current low-supply environment, but it worked once and it will hopefully work again once supply returns.
One very important component to this: having the car inspected by an independent third party. In all (non-local) cases I was able to locate an independent repair place that would look at the car and send me a report. Levels of detail varied, some shops were set up for this and sent me a novel, others were lighter on fine details. I usually paid $50-200 for the service and I wouldn't buy a car without such an inspection.