So far it seems that rank, division, position, and posting all have to do with who gets command and when.
You'd think they would clash, but they don't, at least most of the time.
When Riker got promoted to captain, he actually considered Worf for the position of first officer, before he even considered Data.
As second officer, it would be assumed that Data would automatically get the first officer position since it's like he's a first officer in training.
Riker totally skips this idea and considers promoting others.
I believe the reason was since Data was already slated to become First Officer of the Enterprise under Picard, this was pretty much stated in Nemesis