He must pitch a minimum of 5 complete innings.
There is no limit in regards to how many innings a Starting Pitcher must pitch in the Major League Baseball All Star game, a team can be winning and the Starting Pitcher could pitch only 2 innings but because All Star games have different rules, they can be given the Win.
Four consecutive innings if she is the starting pitcher. There's no minimum number required for relief pitchers.
A starting pitcher needs to pitch at least 5 innings to get the win. Any subsequent pitcher can get the win even if he only retires one batter (or base runner). If the starting pitcher leaves with the lead but without pitching 5 innings, and his team maintains that lead, the official scorer can decide which pitcher to give the win to.
In a Major League Baseball game, Starting Pitchers can pitch as many innings as needed, it is up to the discretion of his Manager however Starting Pitchers must pitch 5 innings in order to qualify for a win.
Unlike the starting pitcher, a relief pitcher has no minimum number of innings pitched. Given the definition of a win, however, it's impossible for a pitcher to achieve it without pitching at least 0.1 inning (one out).