我有一个名为stock sales的mysql表,它有3列,我想用单个语句插入数据。
"INSERT INTO stock_sales (size) SELECT size FROM stock_avail WHERE id='5957';
"INSERT INTO stock_sales (transactionid, date) VALUES ('$bill','$date')";
答案 0 :(得分:2)
$sqlQuery = "INSERT INTO stock_sales (size) SELECT size FROM stock_avail WHERE id='5957';";
$sqlQuery. = "INSERT INTO stock_sales (transactionid, date) VALUES ('$bill','$date')";
mysqli_multi_query($con,$sqlQuery);
mysqli_multi_query()函数执行一个或多个查询 数据库。查询用分号分隔。
有关详情,请点击Mysqli_Multi_Query - W3 Schools
答案 1 :(得分:1)
尝试:
INSERT INTO stock_sales (size, transactionid, date)
SELECT size, '$bill', '$date'
FROM stock_avail
WHERE id='5957'
或
INSERT INTO stock_sales (transactionid, date, size)
VALUES ('$bill', '$date', (SELECT size FROM stock_avail WHERE id='5957'))