简体   繁体   English

连接两个没有公共列的表

[英]Joining two tables with no common column

I want to join two tables together combing two fields in table 1 to form composite keys and combining two fields in table 2 to form composite keys. 我想将两个表连接在一起,组合表1中的两个字段以形成组合键,并组合表2中的两个字段以形成组合键。

The primary keys will be dropped because tables get truncated in ETL 因为在ETL中表被截断,所以将删除主键

CREATE TABLE collection]
(
    collectionid INT NOT NULL PRIMARY KEY,
    spaceid INT NOT NULL,
    collectionpa VARCHAR(150) NOT NULL,
    collectionto VARCHAR (150) NOT NULL
)

CREATE TABLE objects
(
    birstobj INT NOT NULL PRIMARY KEY
    birstspace INT NOT NULL,
    collectionid INT NOT NULL,
    object_nm VARCHAR(150) NOT NULL,
    object_label VARCHAR (150)NOT NULL
)

composite keys in table 1 spaceid and collectionpa composite keys in table 2 birstspace and collectionid 表1 spaceid和collectionpa中的组合键表2 birstspace和collectionid中的组合键

A join condition is just like any other SQL condition - you can use both the columns there: 连接条件与任何其他SQL条件一样-您可以在此处使用两列:

SELECT *
FROM   collection c
JOIN   object o ON c.collectionid = o.collectionid AND
                   c.spaceid = o.birstspace

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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