对于这两个表:
CREATE TABLE TEST1 ( ID INTEGER ,key VARCHAR(50),VALUE1 VARCHAR(50));
CREATE TABLE TEST2 ( ID INTEGER ,key VARCHAR(50),VALUE2 VARCHAR(50));
表格1:
130, 'HANSEN', 'STREET1'
130, 'HANSEN', 'STREET2'
130, 'HANSEN', 'STREET3'
120, 'HANSEN', 'STREET5'
120, 'HANSEN', 'STREET6'
表2:
130, 'HANSEN', 'ZIP1'
130, 'HANSEN', 'ZIP2'
130, 'HANSEN', 'ZIP3'
120, 'HANSEN', 'ZIP4'
120, 'HANSEN', 'ZIP5'
是否有可能获得如下输出:
130, 'HANSEN', 'ZIP1','STREET1'
130, 'HANSEN', 'ZIP2','STREET2'
130, 'HANSEN', 'ZIP3','STREET3'
120, 'HANSEN', 'ZIP4','STREET5'
120, 'HANSEN', 'ZIP5','STREET6'
尝试在 id、key 上进行内部连接,但我得到了笛卡尔积
感谢您的帮助。
辅助脚本(如果有人愿意测试它):
DROP TABLE TEST1;
DROP TABLE TEST2;
CREATE TABLE TEST1 ( ID INTEGER ,key VARCHAR(50),VALUE1 VARCHAR(50));
CREATE TABLE TEST2 ( ID INTEGER ,key VARCHAR(50),VALUE2 VARCHAR(50));
INSERT INTO TEST1 VALUES (130, 'HANSEN', 'STREET1');
INSERT INTO TEST1 VALUES (130, 'HANSEN', 'STREET2');
INSERT INTO TEST1 VALUES (130, 'HANSEN', 'STREET3');
INSERT INTO TEST1 VALUES (120, 'HANSEN', 'STREET5');
INSERT INTO TEST1 VALUES (120, 'HANSEN', 'STREET6');
INSERT INTO TEST2 VALUES (130, 'HANSEN', 'ZIP1');
INSERT INTO TEST2 VALUES (130, 'HANSEN', 'ZIP2');
INSERT INTO TEST2 VALUES (130, 'HANSEN', 'ZIP3');
INSERT INTO TEST2 VALUES (120, 'HANSEN', 'ZIP4');
INSERT INTO TEST2 VALUES (120, 'HANSEN', 'ZIP5');