我试图用1个mysql命令将2个表连接成1个表。我还想将文件路径连接到新表中的一个路径。任何信息都有帮助。谢谢。
这样的事情:
INSERT INTO table3 VALUES (Location) SELECT "A.Loc_Path B._FilePath" FROM Table2 A INNER JOIN table1 B ON A._Loc_ID = B._Loc_ID
我想采取表1和表1 2并创建表3
表1
| ID | _FilePath | _Loc_ID |
| 1 | 001\yay\txt.html | 1 |
| 1 | 002\yay\txt.php | 2 |
表2
| _Loc_ID | Loc_Path |
| 1 | D:\documents\test\ |
| 2 | C:\Temp\test\ |
表3
| Id | Location |
| 1 | D:\documents\test\001\yay\txt.html |
| 2 | C:\Temp\test\002\yay\txt.php |
答案 0 :(得分:3)
使用concat
INSERT INTO table3 (Location) SELECT concat (A.Loc_Path , B._FilePath)
FROM Table2 A INNER JOIN table1 B ON A._Loc_ID = B._Loc_ID
答案 1 :(得分:2)
您需要使用concat function来连接两列:
INSERT INTO table3 VALUES (Location) SELECT CONCAT(A.Loc_Path, B._FilePath) FROM
Table2 A INNER JOIN table1 B ON A._Loc_ID = B._Loc_ID