简体   繁体   中英

How to write a MySQL Insert Into Statement with Inner Join?

The user adds information here: the form

The information gets added to the shoes table.

The database: the database

I want to insert ShoeImage, ShoeName, ShoeStyle, ShoeColor, ShoePrice, and ShoeDescr, and NOT ShoeID (which is autoincrement),ShoeBrandID, and ShoeSizeID.

My insert statement:

$sql = "INSERT INTO $tblShoes VALUES (NULL, '$ShoeImage', '$ShoeName', '$ShoeStyle', '$ShoeColor',
                        '$ShoePrice', '$ShoeDescr')";

How to write this insert statement with inner join?

Might works.

INSERT INTO shoes
(
'ShoeImage',
'ShoeName',
'ShoeStyle',
'ShoeColor',
'ShoePrice',
'ShoeDescr',
'ShoeBrandID',
'ShoeSizeID'
)
VALUES(
NULL,
'$ShoeImage',
'$ShoeName',
'$ShoeStyle',
'$ShoeColor',
'$ShoePrice',
'$ShoeDescr',
(SELECT BrandID FROM shoebrand WHERE BrandName = '$ShoeBrand'),
(SELECT SizeID FROM shoesize WHERE Size = '$ShoeSize')
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM