kaiki
V2EX  ›  问与答

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

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