View with ALGORITHM (MySQL)
View with ALGORITHM (MySQL) is a SQL statement in the Views category. MySQL: controls how the view is executed — MERGE (inline), TEMPTABLE (materialized), UNDEFINED (optimizer chooses). The syntax is CREATE ALGORITHM = MERGE | TEMPTABLE | UNDEFINED VIEW view_name AS select_statement;. It returns view with algorithm. A typical example: -- MERGE (default): view query is merged with outer query CREATE ALGORITHM = MERGE VIEW dept_employees AS SELECT * FROM employees WHERE department IN ('IT', 'HR'); -- WHERE conditions on the view are combined with the view definition -- TEMPTABLE: view results are stored in a temp table first CREATE ALGORITHM = TEMPTABLE VIEW expensive_products AS SELECT * FROM products WHERE price > 100; -- Better for complex views with… A close relative is CREATE VIEW, which creates a virtual table based on a SELECT query. Think of it as a saved query that acts like a table.