第一张表
$sql = "CREATE TABLE if not exists mainInfo (
sku varchar(20) primary key not null,
name varchar(20) not null,
price int(30) not null,
type int(2) not null
)";
第二个表
$sql="CREATE TABLE if NOT EXISTS properties (
size int(9),
bWeight int(9),
fHeight int(9),
fWeight int(9),
fLenght int(9),
sku varchar(20) not null,
CONSTRAINT FK_mainInfoProperties FOREIGN KEY (sku) REFERENCES mainInfo(sku)
)";
内连接表
$sql = "CREATE TABLE if NOT EXISTS allInfo (
sku varchar(20) primary key not null,
name varchar(20) not null,
price int(30) not null,
type int(2) not null,
size int(9),
bWeight int(9),
fHeight int(9),
fWeight int(9),
fLenght int(9)
)";
$sql = "INSERT INTO allInfo (sku, name, price, type, size, bWeight,
fHeight, fWeight, fLenght)
SELECT mainInfo.sku, name, price, type, size, bWeight, fHeight,
fWeight, fLenght
FROM mainInfo INNER JOIN properties
ON mainInfo.sku = properties.sku";
我第一次使用这段代码是可行的,但是当我向第一个和第二个表添加新行时,内部连接表没有更新它,给了我键'PRIMARY‘的重复条目,我如何才能更新这个表,添加新的行,而不改变已经存在的行?
发布于 2018-07-01 00:15:34
我想你不需要第三张桌子。您可以使用简单的join轻松地获得唯一记录。
Select m.sku ,a.bWeight, a.fHeight, a.fWeight , a.fLenght from mainfon join properties a on m.sku=a.suk where a.suk=your_id
我建议两个人只用两张桌子,不要用第二张
https://stackoverflow.com/questions/51115872
复制相似问题