开发者

Create tables by JOINing two tables using a third

开发者 https://www.devze.com 2023-03-29 02:57 出处:网络
I have three tables: TABLE 1 (7.7million records) ID_1|..|..| OTHER FIELDS| TABLE 2 (8.2 million records)

I have three tables:


TABLE 1 (7.7million records)

ID_1|..|..| OTHER FIELDS|


TABLE 2 (8.2 million records)

ID_2 |..|..|.....


TABLE 12 (7.5 million records)

ID_1| ID_2 | SOMEFIELDS| AND ID_1== ID_2.i.e. contains all common ids

The table 12 contains unique ids which are common to table 1 and 2. I am trying create a new table to get all data from t1 and t2 by matc开发者_开发知识库hing which records in t12 with id_1,id_2).

Following is the sql Iam using:

CREATE TABLE ARROW_all_common12 AS 
SELECT T1.*, T2.* FROM T1, T2
LEFT JOIN T12 
ON T12.ID_1=T1.ID_1
LEFT JOIN T12
ON T12.ID_2 = T2.ID_2
WHERE T12.ID2 = T2.ID_2


I'm not entirely sure what you're asking here, but maybe a view could be what you're looking for?

CREATE VIEW someview AS (
    SELECT t1.*, t2.*
    FROM table12 AS t12
    INNER JOIN table1 AS t1
        ON t1.id_1 = t12.id1
    INNER JOIN table2 AS t2
        ON t12.id_2 = t2.id_2
)


same, it's not quite clear. maybe that?

create table t_all_12 as (
      select t1.*, t2.* 
      from t1, t2, t12
      where t12.id_1 = t1.id_1
      and t12.id_2 = t1.id_2
)
0

精彩评论

暂无评论...
验证码 换一张
取 消