CREATE TABLE table1 (id varchar(10),name varchar(10))CREATE TABLE table2 (id varchar(10),name varchar(10)) INSERT INTO table1 VALUES ("1", "John"), ("1", "Merry"), ("2", "Ted"), ("3", "Jack"), ("3", "Zed"); INSERT INTO table2 VALUES ("1234", "John"), ("1234", "Peter"), ("1236", "Gerry"), ("1237", "Grey"), ("1237", "Zed")
SQL Fiddletable1
idname1John1Merry2Ted3Jack3Zed
table2
idname1234John1234Peter1236Gerry1237Grey1237Zed
我要这二张表合起來,而且将一起发生在 table1 与 table2 名字所相匹配 id 归成同一类
idnamec1John11Merry12Ted23Jack33Zed31234John11234Peter11236Gerry12361237Grey31237Zed3