This topic describes how to query data from a materialized view by using syntax such as SELECT, INSERT INTO SELECT, and WITH.

Required permissions

You must have SELECT permissions on materialized views. You do not need to have SELECT permissions on the base tables referenced by materialized views.
Note You can use GRANT to grant SELECT permissions on materialized views to users.
GRANT SELECT ON <mv_name> TO '<user>'@'%';

Procedure

The statement used to query data from a materialized view is the same as that used to query standard tables or views. You can use materialized views in all query syntax. Sample syntax:
SELECT * FROM adbview
WHERE device = 'PC'
  AND city = 'Beijing';
Note When you perform queries by using materialized views, base tables referenced by the materialized views may be updated, but the updates are not reflected in the materialized views. In this case, the query results may be inaccurate. For this reason, we recommend that you manually refresh materialized views after their base tables are updated and then perform queries. For more information about how to manually refresh materialized views, see Refresh materialized views.