[英]About joining two table with unique index
I have two table like this 我有两个这样的桌子
table "X" 表“ X”
idX(pk) contentX(char)
10 foo1
21 foo2
34 foo3
45 foo4
table "Y" 表“ Y”
idY(pk) contentY(char)
11 boo1
22 boo2
33 boo3
40 boo4
And after joining, intsert to a table and become this 加入后,插入一张桌子成为这个
idNew(pk) idX(UQ) content(char) idY(UQ) content(char)
1 10 foo1 11 boo1
2 21 foo2 22 boo2
3 34 foo3 33 boo3
4 45 foo4 40 boo4
The SQL I use is like this 我使用的SQL是这样的
INSERT INTO DataBase.newtable(idX, contentX,idY,contentY)
SELECT X.idX, Y.idY, contentX, contentY
FROM DataBase.X, DataBase.Y, ;
But the SQL statement cannot insert to newtable because the idX and idY is needed to be unique value. 但是SQL语句不能插入到newtable中,因为idX和idY必须是唯一值。 What can I do?
我能做什么?
You need to specify the join field for that insert, otherwise you are going to get the Cartesian product of both tables (Ie 16 rows). 您需要为该插入指定连接字段,否则将获得两个表的笛卡尔积(即16行)。 If you have unique indexes on the idx and idy fields, this constraint would cause insert to fail.
如果在idx和idy字段上具有唯一索引,则此约束将导致插入失败。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.