Create View in MySQL

To create a new view in MySQL, you use the CREATE VIEW statement. The syntax of creating a view in MySQL is as follows:

CREATE
   [ALGORITHM = {MERGE  | TEMPTABLE | UNDEFINED}]
VIEW[database_name].[view_name]
AS
[SELECT  statement]

Sample:

CREATE VIEW SalePerOrder AS
 SELECT orderNumber, 
 SUM(quantityOrdered * priceEach) total
FROM orderDetails
GROUP by orderNumber
ORDER BY total DESC;

,

No comments yet.

Leave a Reply

*