A second officer is typically the highest ranked and trusted officer aboard, below the captain and XO. He or she assums command of the ship when both the captain and first officer are unavailable. Second officers on Starfleet vessels commonly hold the rank of lieutenant commander, though it is not rare for one to be a lieutenant or even a full commander. The second officer's rank may never exceed that of the first officer or captain.
The second officer is a department head aboard the ship first, and a second officer second. He or she is rarely involved in the day to day command of the starship or starbase the way the captain or first officer is.
It is standard procedure for the second officer to accompany an away team.