the question is
Which of the following methods for providing explicit names for the columns in a view work? a. Include a column list b. Provide column aliases in the view SELECT statement c. Rename the columns when you select from the view
answer
a. Works: Include a column list b. Works: Provide column aliases in the view SELECT statement c. Does not work: Rename the columns when you select from the view
regarding (c) what do they mean by “Rename the columns when you select from the view”?
I think the question in the certification guide is worded poorly. You can give explicit names to columns when you select from a view, and this works:
The problem is not with giving aliases to columns explicitly. Here’s the problem: if you rely on this instead of defining the view with distinct column names, and the view consists of a join such that the column names are ambiguous, you run into trouble:
This is not a valid view, because in the view definition, all column names must be distinct. For instance, you would get ambiguous results when you query the view:
Does this select the first
acolumn or the secondacolumn?So you must have a distinct set of column names in the view definition, it’s not enough to make them distinct as you query the view.
This is the reason I think the certification guide question was poorly worded. It’s not about renaming columns explicitly, it’s about ensuring that the columns of the view have distinct names. This is a common reason for renaming columns, so that’s probably why the person writing the question wrote it that way.
Either of the other techniques mentioned in the question can resolve the ambiguity:
or
Either way, you get the aliased columns: