dongxi1879 2014-06-06 06:47
浏览 64
已采纳

您无法在MySQL中的FROM子句中指定要更新的目标表

I want to change the status of a single order by selecting its requisition_id where the status matches a specific keyword. But it keeps showing me this error "You can't specify target table for update in FROM clause"

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

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>';
  • 写回答

1条回答 默认 最新

  • drl959975 2014-06-06 06:50
    关注

    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:

    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'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)