当表中已有这个userid时,我就不会向表中插入这行记录
求insert语句

解决方案 »

  1.   

    insert into table1 select * from table2 where userid not in(select userid from table1)
      

  2.   

    insert tb(userid) selct * from(userid = '要插入的userid') a
    where not exists(
        select * from tb where userid = a.userid)
      

  3.   

    insert into @table1
    select table2.* 
    from table2 left outer join table1
    on table2.userid=table1.userid where table1.userid is null
      

  4.   

    insert into table1
    select table2.*
    from table2 left outer join table1
    on table2.userid=table1.userid where table1.userid is null
      

  5.   

    declare @table1 table(userid int,col1 int)
    insert into @table1
    select 1,1
    union select 2,2
    union select 3,3
    union select 4,4
    select * from @table1
    declare @table2 table(userid int,col1 int)
    insert into @table2
    select 1,1
    union select 2,2
    union select 3,3
    union select 4,4
    union select 5,5
    select * from @table2insert into @table1
    select table2.* 
    from @table2 table2 left outer join @table1 table1
    on table2.userid=table1.userid where table1.userid is nullselect * from @table1;
      

  6.   

    insert into table1 select 要插入1,要插入2,... where ...中要插入userid的值 not in(select userid from table1)
      

  7.   

    这就是insert 后面能不能带where 的问题,要带where 必需将valuse 转换为select 的形式
      

  8.   

    insert  tb_xiangcestory_black(userid) select * from(userid = 1122) a
    where not exists(
        select * from tb_xiangcestory_black where userid = a.userid)消息 102,级别 15,状态 1,第 2 行
    '=' 附近有语法错误。
      

  9.   

    insert into tb_xiangcestory_black(userid) select 1122 where 1122 not in(select userid from tb_xiangcestory_black)