If efficiency is not a big concern, two schottky diodes (one on each input) will do the job... the highest voltage will win.
There are ideal diodes you could use to keep it as efficient as possible, but a lot of them only work up to 5.5v-6v... so if you want to use them you'd have to lower the voltage to 5v or less and then feed them to one of these ideal diodes.
For example, LM66200 -
https://www.ti.com/lit/ds/symlink/lm66200.pdf - is a dual ideal diode package, and it automatically puts on the output the higher voltage out of the two.
It would be great to auto switch between USB input and internal battery for example, both voltages lower than the maximum 5.5v it can handle
The IC has an enable pin that's active low, so if it gets some voltage on the OE pin it would turn off the output so I suppose that could work for you in an indirect way (for example 9v in - buck regulator to 5v or 3.3v - connect output to OE pin - when you plug 9v in then the ideal diode disconnects and the two inputs on the ideal diode are disconnected
Link :
https://www.digikey.com/en/products/detail/texas-instruments/LM66200DRLR/15856663There's also a single diode version LM66100 that has an EN pin ... you can use two of them and interconnect them to get a dual ideal diode package
Link :
https://www.digikey.com/short/dhpbzfz9 MAX40200 is another example of an ideal diode, which goes only up to 1A - 1.2A :
https://www.digikey.com/short/890zf1jb (it's also available on LCSC cheaper)
There's also power switch ICs which can select between two or more inputs.
One good example, TPS22933 :
https://www.digikey.com/en/products/detail/texas-instruments/TPS22933ARSET/3725886 https://www.ti.com/lit/ds/symlink/tps22933.pdfHas three inputs (up to 12v) and auto selects highest of the three , and also has a built in LDO that can output 3.6v up to around 75mA that you could use a sort of stand-by power if you need to.
Other examples ... TPS21**
TPS2111APWR - 4.5A , up to 5.5v
https://www.digikey.com/en/products/detail/texas-instruments/TPS2111APWR/652781 TPS2115APWR and TPS2115ADRBR (different footprints, same ic)
https://www.digikey.com/en/products/detail/texas-instruments/TPS2115APWR/652785 - 1.25A, 5.5v
https://www.digikey.com/en/products/detail/texas-instruments/TPS2115ADRBR/1843509 - 2A , 5.5v
TPS2121RUXR - 4.5A , 22v
https://www.digikey.com/en/products/detail/texas-instruments/TPS2121RUXR/9859001https://www.digikey.com/en/products/detail/texas-instruments/TPS2121RUXR/9859001