A function aboard a starship, a second officer assumes command of the ship when both the captain and first officer are unavailable. It is common for a second officer on a Starfleet vessel to hold the rank of lieutenant commander. 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 the away team.