Views of Mysql and views of Mysql

Source: Internet
Author: User

Views of Mysql and views of Mysql
View operations: 1. view creation: create view view_name as query statement; 2. view: show tables; // show all tables and views show create view view_name; desc view_name; show table status from table_name like 'view _ name'; 3. use a view (similar to a query TABLE statement); select * from view_name (where condition); 4. view modification: alter view view_name as query statement; create or replace view view_name as query statement; 5. view deletion: drop view view_name; 6. view classification: (1 ). constant view: create view view_name as select constant; example: create view view_test1 as select 3.1415926; query: select * from view_test1; (2 ). aggregate functions (SUM, MIN ., MAX, COUNT, etc.) query statement view: create view view_name as select function (attribute name) from table_name; example: create view test2 as select count (name) from t_student; (3 ). view of the sorting function: create view view_name as select attribute name from table_name order by attribute name order; the order is divided into DESC and ASC, the former is in descending order, and the latter is in ascending order. (4 ). join query statement in the Table: create view view_name as select attribute from table1_name, table2_name where condition; example: create view view_testt4 as select s. name from t_student as s, t_group as g where s. group_id = g. id and g. id = 2; The as after table_name indicates the alias; (5 ). table Outer JOIN (left join and right join) query statement: create view view_name as select attribute name from table1_name left join table2_name on condition where condition; left join, example: create view view_test5 as select s. name from t_student as s left join t_group as g on s. group_id = g. id where g. id = 2; (6 ). subquery related query statement: create view view_name as select attribute name from table1_name where attribute name in (select attribute name from table2_name); example: create vieww view_test6 as select s. name from t_student as s where s. group_id in (select id from t_group); (7 ). UNION and union all: create view view_name as query statement 1 union all query statement 2; the query content should be the same.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.