SQL - Create view from multiple tables

mysql, postgresql, sql

Solution

Thanks for the help. This is what I ended up doing in order to make it work.

CREATE VIEW V AS
    SELECT *
    FROM ((POP NATURAL FULL OUTER JOIN FOOD)
    NATURAL FULL OUTER JOIN INCOME);

Problem

I have three tables: ``` POP(country, year, pop) FOOD(country, year, food) INCOME(country, year, income) ``` I am trying to create a view such as: ``` V(country, year, pop, food, income) ``` This is my code so far. I don't think its correct: ``` CREATE VIEW V AS (SELECT * FROM POP UNION SELECT * FROM FOOD UNION SELECT * FROM INCOME); ``` One issue is, a country that is present in `POP` may not be present in `FOOD`. Same goes for year. A year that is present in `POP` may not be present in `FOOD`. So, I keep thinking that the above code will not work.

Original source