zoukankan      html  css  js  c++  java
  • 关于一张表数据插入到另一张表保持数据唯一,不重复

    insert into a2 (c1,c2)
    select c1,c2 from a where Deleted=1


    能提供一些思路吗..或者mysql本身能解决吗

    假如表中已存在该数据则不能插入该数据,不存在就插入
    网友回复:先在a2表中查找你要插入的数据,假如能找到就说明有重复数据,不要插入。
    网友回复:sql 语句能解决吗 例如distinct , if exists
    网友回复:一條語句搞定,不過不知道MSSQL的寫法與MySQL的是否一致
    SQL code
    Code highlighting produced by Actipro CodeHighlighter (freeware)
    http://www.CodeHighlighter.com/
    insert   into   a2   (c1,c2)
    select   c1,c2   from   a
    left join a2 on a.c1=a2.c1 and a.c2=a2.c2
    where   Deleted=1 and (a2.c1 is null and a2.c2 is null)
     
    如果是一个主键我可以用   not   in   来判断,     
      但是两个键如何写  
      我试用exists来,   但写不好,   它只判断存不存在,   到底怎么写大家教我
    网友回答:
    网友:tj_dns

    insert   b  
      select   *   from   a   where   not   exists   (select   *   from   b   where   k1   =   a.k1   and   k2   =   a.k2)

    网友:pengdali

    insert   b   select   *   from   a   where   not   exists   (select   1   from   b   where   k1   =   a.k1   and   k2   =   a.k2)

     
    
    
    
  • 相关阅读:
    ★★★
    ★★
    小狼程序员:工作遐想
    广联达BB了
    计算机网络简单理解
    做个合格的(优秀的)测试开发人员
    开发、测试、测试开发
    8.21
    C++ 选择题总结(回调函数 || 类方法(实例方法)|| )
    深拷贝实现笔记
  • 原文地址:https://www.cnblogs.com/chengulv/p/1057518.html
Copyright © 2011-2022 走看看