简体   繁体   中英

sql create a view combining two tables

Table 1

id DATE column1 column2

.

Table 2

id DATE column1 column2

The output I want is:

DATE {column1 from Table 1} {column2 from Table 2}

Obviously the DATE column is common for the two tables, the data from column1 & column2 differs I tried with create view and union from the two tables but the result is that it combines {column1 from Table 1} and {column2 from Table 2} into one column while what i want is these two to be created as two seperate columns

What you're looking for is a simple join .

create view yourview as
  select t1.date, t1.column1, t2.column2
    from table1 t1
      inner join table2 t2
        on t1.date = t2.date

This assumes that you want column 1 from table1, column 2 from table2, where they share a common date.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM