[英]You can't specify target table for update in FROM clause in MySQL
I want to change the status
of a single order by selecting its requisition_id
where the status
matches a specific keyword. 我想改变status
,通过选择它的单个订单的requisition_id
在status
特定的关键字匹配。 But it keeps showing me this error "You can't specify target table for update in FROM clause" 但是它不断向我显示此错误“您无法在FROM子句中指定目标表进行更新”
UPDATE order_info
SET status ='Approved'
WHERE requisition_no IN (SELECT requisition_no FROM order_info WHERE status = 'not approved')
What can I do to fix it? 我该如何解决?
EDIT- I've included the PHP code as well 编辑-我也包括了PHP代码
while ($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['requisition_no'] . "</td>";
echo "<td>" . $row['desig'] . "</td>";
echo "<td>" . $row['deptt'] . "</td>";
echo "<td>" . $row['type'] . "</td>";
echo "<td>" . $row['make'] . "</td>";
echo "<td>" . $row['quantity'] . "</td>";
echo '<form method="post" action="status.php">'; /*Redirects to status.php to change the status (using diff. page because i'm a hopeless kid, who doesnt want to learn new ways of simplifying things)*/
echo "<td>" . $row['status'] . "<br/>";
if($row['status']=='Approved' || $row['status']=='Under Procurement'){//does nothing
}
/*Here, using a submit button*/
else { echo '<input type="submit" name="status" value="Approve"></td>';
$_SESSION['rno'] = $row['requisition_no'];}
echo '</form>';
You have a few syntax errors probably causing this error. 您有一些语法错误可能会导致此错误。 You are missing an equals sign =
after status
and the right parenthesis )
at the end: 在status
末尾加上右括号( )
后,您缺少等号=
:
UPDATE order_info o
SET o.status = 'Approved'
WHERE o.requisition_no IN (SELECT x.requisition_no FROM (select * from order_info) x WHERE x.status = 'not approved')
Also, I think your query can be rewritten like this: 另外,我认为您的查询可以这样重写:
UPDATE order_info
SET status = 'Approved'
WHERE status = 'not approved'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.