V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
kaiki
V2EX  ›  问与答

mysql 如何查询 a 表中所有的 id 并写入 b 表数据

  •  
  •   kaiki · Dec 22, 2020 · 1030 views
    This topic created in 1954 days ago, the information mentioned may be changed or developed.
    就写入 id 就行,之后弄个触发器让它新增自动写入好了。
    可以的话跳过已存在的 id 数据
    kaiki
        1
    kaiki  
    OP
       Dec 22, 2020
    算了,想起来了
    insert into b(m_id) select id from a where id not in(select id from b);
    kaiki
        2
    kaiki  
    OP
       Dec 22, 2020
    @kaiki 打错了
    insert into b(id) select id from a where id not in(select id from b);
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1044 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 18:47 · PVG 02:47 · LAX 11:47 · JFK 14:47
    ♥ Do have faith in what you're doing.