mysql Query中的更新错误从另一个表中获取数据

时间:2017-12-05 06:59:57

标签: mysql

我正在尝试更新位置表中的 orgaization_id ,这是组织表中的主键。

    <html>
    <head>
      <title>Swipe tab</title>
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js"></script>
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-mobile/1.4.5/jquery.mobile.js"></script>
      <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-mobile/1.4.5/jquery.mobile.min.css">
    </head>
    <body>
    <div data-role="page" id="lessonhomepage">
      <!--content start-->
      <div data-role="content" id="tabscontent">
        <!--horizontal navigation tab start-->
        <div data-role="tabs" id="tabs">
          <div data-role="navbar" id="nav">
            <ul>
              <li><a class="ui-btn-active" href="#study" data-ajax="false">Study</a>
              </li>
              <li><a href="#quicktips" data-ajax="false">Quick Tips</a>
              </li>
              <li><a href="#quicktips3" data-ajax="false">Quick Tips</a>
              </li>
              <li><a href="#quicktips4" data-ajax="false">Quick Tips</a>
              </li>



            </ul>
          </div>
          <div id="study">
            Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
          </div>
          <div id="quicktips">
           There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.
          </div>
          <div id="quicktips3">
           There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.
          </div>
          <div id="quicktips4">
           There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.
          </div>
          <div id="quicktips5">
           There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.
          </div>
          <div id="quicktips6">
           There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.
          </div>




          <!--horizontal navigation tab end-->
          <br/>
        </div>
      </div>
    </div>
    <script type="text/javascript">
     var panel = '<div data-theme="a" data-role="panel" data-display="overlay" id="leftpanel">sdf</div>';

     $(function() {
       $("body").prepend(panel);
       $("[data-role=panel]").panel().enhanceWithin();
     });

     var nextidx = 0;

     function changeNavTab(left) {
       var $tabs = $("div[data-role=navbar] li a", $("div[data-role=page].ui-page-active"));
       var curidx = $tabs.closest("a.ui-btn-active").parent().index();

       var tabcount = $tabs.length;

       if (left) {

           if (nextidx == tabcount - 1) {
               return(false);           
            } 
           else {
            nextidx = (curidx == $tabs.length - 1) ? 0 : curidx + 1;

            }

       } else {
          if (nextidx ==  0) {

               return(false);
            } 
           else {
               nextidx = (curidx == 0) ? $tabs.length - 1 : curidx - 1;

            } 

       }
       $tabs.eq(nextidx).click();
     }

     $("div[data-role=content]").on("swipeleft", function(event) {
       changeNavTab(true);
     });
     $("div[data-role=content]").on("swiperight", function(event) {
       changeNavTab(false);
     });


     // Navigation  Drawer Swipe Listener
     $("div[data-role=header]").on("swipeleft swiperight", function(e) {
       // save swipe direction right/left
       var dir = 'prev';
       if (e.type == 'swiperight') {
         dir = 'next';
       }
       if (dir == 'prev') {
         $('#leftpanel').panel('close');

       } else {
         $('#leftpanel').panel('open');

       }
     });

    </script>
    </body>
    </html>

面对语法错误,请帮助..

2 个答案:

答案 0 :(得分:1)

您可以使用join从另一个表执行更新

update location l
join organization as o
on l.old_id=o.old_id
set l.organization_id=o.old_id;

答案 1 :(得分:0)

请尝试以下代码:

update location set organization_id=(select old_id from organization where organization.old_id=location.old_id);