So I want to condense this query and I'm not sure how to go about it.
Right now I use
$move_to_sold =
"INSERT INTO sold_inv_item(
`sku`,
`designer`,
`type`,
`price`,
`metal_type`,
`stone_type`,
`stone_weight`,
`item_desc`,
`item_img`
)
SELECT
`sku`,
`designer`,
`type`,
`price`,
`metal_type`,
`stone_type`,
`stone_weight`,
`item_desc`,
`item_img`
FROM inv_item
WHERE `sku` = '$sku'";
$add_date_and_name =
"UPDATE sold_inv_item
SET `purchase_date` = '$date', `customer_name` = '$name'
WHERE `sku` = '$sku'";
what I'm trying to do is copy a row from 1 table to another, and then add additional data into the 2 extra columns from $_POST data.
I tried something like
INSERT INTO sold_inv_item(`sku`,`designer`,`type`,`price`,`metal_type`,
`stone_type`,`stone_weight`,`item_desc`,`item_img`,`purchase_date`,`customer_name`)
VALUES ((select `sku`,`designer`,`type`,`price`,`metal_type`,
`stone_type`,`stone_weight`,`item_desc`,`item_img` FROM inv_item WHERE inv_item.sku = 'pepsi-2-tone'), '2019-02-14','betty Girl');
This gives a column mismatch error, I suspect because it's trying to fit all the rows into 1 column instead of spreading them out.
Finally this works but I'd rather do something like the middle solution if possible.
INSERT INTO sold_inv_item(`sku`,`designer`,`type`,`price`,`metal_type`,
`stone_type`,`stone_weight`,`item_desc`,`item_img`,`purchase_date`,`customer_name`)
VALUES ((select `sku` from inv_item where inv_item.sku = 'pepsi-2-tone'),
(select `designer` from inv_item where inv_item.sku = 'pepsi-2-tone'),
(select `type` from inv_item where inv_item.sku = 'pepsi-2-tone'),
(select `price` from inv_item where inv_item.sku = 'pepsi-2-tone'),
(select `metal_type` from inv_item where inv_item.sku = 'pepsi-2-tone'),
(select `stone_type` from inv_item where inv_item.sku = 'pepsi-2-tone'),
(select `stone_weight` from inv_item where inv_item.sku = 'pepsi-2-tone'),
(select `item_desc` from inv_item where inv_item.sku = 'pepsi-2-tone'),
(select `item_img` from inv_item where inv_item.sku = 'pepsi-2-tone'),'2019-02-14','betty Girl');
So finally the question is, what is the most effective way code and performance wise to copy a row from one table to another and fill additional columns. There a few similar ones but none that I can find cover more than 1-2 columns being copied over.