Sunday, 19 February 2012

Q: How can create views in mysql.


Ans: In SELECT statement, you can query any tables or views existed in the database. There are several rules which SELECT statement has to follows:
  • Subquery cannot be included in the SELECT statement.
  • Any variables such as local, user and session variables cannot be used in the SELECT statement.
  • The prepared statement cannot be used in the view.
  • Temporary tables or views cannot be used in the SELECT statements and any tables or views which referred by views must exists.
  • View cannot be associated with triggers
CREATE VIEW SalePerOrder

   AS

  SELECT orderNumber,

  SUM  (quantityOrdered * priceEach) total

  FROM orderDetails

  GROUP by orderNumber

  ORDER BY total DESC

No comments:

Post a Comment