【问题标题】:Add user if not exists in another table如果另一个表中不存在则添加用户
【发布时间】:2017-08-20 14:36:31
【问题描述】:

如果之前没有将用户名添加到 users 表中,我需要将用户名添加到 users_waiting 表中。

var usernamesArray = ['test', 'test2'];
connection.query('REPLACE INTO users_waiting (username) VALUES ?', [usernamesArray]);

我正在使用node.js mysql client,但我不知道该怎么做。

【问题讨论】:

    标签: mysql node.js node-mysql


    【解决方案1】:

    你有很多选择。 其中之一是NOT EXISTS()

    INSERT INTO <Table2> (...)
    SELECT .... FROM <Source> t
    WHERE NOT EXISTS(SELECT 1 FROM <Table1> s
                     WHERE t.id = s.id);
    

    我不认为这正是您所需要的。但你可以从中找出其余的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-10
      • 1970-01-01
      • 2021-04-04
      • 1970-01-01
      • 2014-02-21
      • 1970-01-01
      • 2014-02-21
      相关资源
      最近更新 更多