比如我有表A,里面有主键为a的数据,
表B,里面有主键为b的数据,
现在我select表a中的数据,用insert插入表b,但是,由于B表中主键唯一,而在A表该键不唯一,所以用distinct取唯一值。
但是,即使这样插入也出错了,为什么?

解决方案 »

  1.   

    比如我有表A,里面有主键为a的数据,
    表B,里面有主键为b的数据,
    现在我select表a中的数据,用insert插入表b,但是,由于B表中主键唯一,而在A表该键不唯一,所以用distinct取唯一值。
    但是,即使这样插入也出错了,为什么?insert into b select distinct id from a where id not in (select id from b)
      

  2.   

    楼上的仁兄,不行哦。
    You have an error in your SQL syntax.  Check the manual that corresp
    onds to your MySQL server version for the right syntax to use near 'select id fr
    om b)' at line 1
      

  3.   

    mysql?我写的是sql server的语法.