The number of columns that you specify in the column list must match the number of columns returned by the SELECT statement that defines the view. If you do not specify a list of columns, the view inherits the column names of the underlying tables. In the following example, the view herostock has the same column names as the columns in Projection clause of the SELECT statement:
CREATE VIEW herostock AS SELECT stock_num, description, unit_price, unit, unit_descr FROM stock WHERE manu_code = 'HRO'
You must specify at least one column name in the following circumstances:
CREATE VIEW newview (firstcol, secondcol) AS SELECT sum(cola), colb FROM oldtab
CREATE VIEW someorders (custnum,ocustnum,newprice) AS SELECT orders.order_num,items.order_num, items.total_price*1.5 FROM orders, items WHERE orders.order_num = items.order_num AND items.total_price > 100.00
Here custnum and ocustnum replace the two identical column names.
For example, code in the following CREATE VIEW statement must specify the column list because the second column in the first SELECT statement has a different name from the second column in the second SELECT statement:
CREATE VIEW myview (cola, colb) AS SELECT colx, coly from firsttab UNION SELECT colx, colz from secondtab