This question already has an answer here:
Is it formally correct to compare two separate models with different independent variables?
For instance in R a pseudo code would be something like:
AIC( lm( y ~ X ) )
AIC( lm( y ~ W ) )
W cannot feature in the same model as for instance
lm( y ~ X*W ) )