Types of views in SQL:
1) Horizontal view: A horizontal view cuts the source tables horizontally to create the view. It creates a horizontal view of the source tables. It is used when different names have to be displayed in a view.
CREATE VIEW NORTHCOM AS SELECT * FROM COMPANIES WHERE REGION = ‘Northern’
The above query creates a view having companies in northern region.
2) Vertical view: A horizontal view cuts the source tables vertically to create the view.
CREATE VIEW EMPLINFO AS SELECT NAME, EMPL_NUM, EMPL_OFFICE FROM EMPLOYEES
The above query creates a view EMPLINFO having name, employee number and office.
3) Row and column views: A row and column view uses both rows and columns to create the view.
CREATE VIEW SPEMPL AS SELECT COMPANY, ORDER_NUM FROM ORDERS WHERE EMPL_NUM = 665
The above query returns all order numbers and company information for employee number 665.
4) Grouped by view: In a grouped by view, a GROUP BY clause is used. A grouped by view always includes a column list.
CREATE VIEW SALPERKS (WHO, PERKS_LIST, AVG_SALARY) AS SELECT NAME, PERKS, AVG(SALARY) FROM EMPLOYEES GROUP BY NAME
where, (WHO, PERKS_LIST, AVG_SALARY) is the column list in view.
5) Joined view: A joined view is used to create a multi table query for a view. The source of this type of view can be two or more tables.
CREATE VIEW ORDERIN (ORDER_NUM, COMPANY, EMPL_NAME, PRICE) AS SELECT ORDER_NUM, COMPANY, NAME, PRICE FROM ORDERS, CLIENTS, EMPLOYEES WHERE CLIENT = CLIENT_NUM AND EMPL = EMPL_NUM