I have a view that works like this:
CREATE VIEW v_myView as SELECT * FROM(
(SELECT a,b,c,d FROM table1)
UNION ALL
(SELECT a,b,c,d FROM table2)
UNION ALL
(SELECT a,b,c,d FROM table3)
.
.
.)
When I use a view, I filter it like this:
SELECT * FROM v_myView WHERE a=x
While this works, it takes an hour (present hour, not figuratively). if I make such a request:
SELECT * FROM(
(SELECT a,b,c,d FROM table1 WHERE a=x)
UNION ALL
(SELECT a,b,c,d FROM table2 WHERE a=x)
UNION ALL
(SELECT a,b,c,d FROM table3 WHERE a=x)
.
.
.)
it takes a minute. which made me wonder if there is a way to get MySql to do this automatically, which means the command WHEREwill work before each table is selected.
source
share