insert INTO tst1(id,snkey,data1) VALUES((select id from tst1 where snkey=7 limit 1 ), 1, 8);

解决方案 »

  1.   

    replace INTO tst1(id,snkey,data1) 
    select id from tst1 where snkey=7 limit 1 , 1, 8;
      

  2.   


    试过了,insert INTO 和 REPLACE INTO 都不可以.
      

  3.   


    你确定上面的insert 执行不成功?在你的select语句外面加一层括号
      

  4.   


    mysql> insert INTO tst1(id,snkey,data1) VALUES((select id from tst1 where snkey=8 limit 1 ), 1, 8);
    1093 - You can't specify target table 'tst1' for update in FROM clause
    mysql> 
      

  5.   

    mysql> replace INTO tst1(id,snkey,data1) VALUES((select id from tst1 where snkey=8 limit 1 ), 1, 8);
    1093 - You can't specify target table 'tst1' for update in FROM clause
    mysql> 
    mysql> replace INTO tst1(id,snkey,data1) select id from tst1 where snkey=7 limit 1 , 1, 8 ;
    1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 8' at line 1
    mysql> 
      

  6.   

    测试语句如下:
    replace into d(a,b,c) values((select a from c limit 1),1,1)
    insert into d(a,b,c) values((select a from c limit 1),1,1)
      

  7.   

    replace INTO tst1(id,snkey,data1) select id,snkey,data1 from tst1 where snkey=7 
    limit 1 , 1 ;
      

  8.   

    那就这样insert into d(a,b,c) select (select a from d where b=1 limit 1), 100, 100
      

  9.   


    insert换成replace能达到要求,谢谢!