Simplest solution as per Sunnyskyguy's response. If you are using low voltage, silicon diode will drop .8V, while germanium drop .3V, so are the best to go for.
The most sophisticated solution is to have a diode derived " Aux line". This then powers an opamp which accurately compares the two power sources and uses a relay to switch from one to another (no voltage drop). Do not think of using a micro processor in this application it offers no advantages over wired up logic and starting from scratch, is very expensive.
Frank