I'm trying to create view that will summarize data in two tables. Each table have several columns, but they both have NAME and AREA columns. And I want these two columns to be united correspondingly in view. I tried to create view using following query:
CREATE VIEW summary AS
INSERT INTO (SELECT Name, SUM(Area) FROM table1 GROUP BY Name)
SELECT *
FROM (SELECT Name, SUM(Area) FROM table2 GROUP BY Name)
But I get the error: SQL error: near "INSERT": syntax error
. Actually I tried different querys involving INSERT INTO and it seems that CREATE VIEW will not work with INSERT INTO, and INSERT INTO does not accept subquery - only existing table (even temporal) would do.
How to rewrite CREATE VIEW statement to achieve my goal?
UNION
orUNION ALL
, notINSERT
:CREATE VIEW summary AS SELECT Name, SUM(Area) FROM table1 GROUP BY Name UNION ALL SELECT Name, SUM(Area) FROM table2 GROUP BY Name ;
– ypercube Mar 29 at 19:14INSERT
is not used in a view create statement in any dialect of SQL I have heard of - aVIEW
is (as the name implies) intended to display data only, not for DML operations. – JNK♦ Mar 29 at 19:23