【问题标题】:Nodejs Mysql Query ChainingNodejs Mysql 查询链
【发布时间】:2021-12-22 07:23:09
【问题描述】:

我想写以下查询

Select id from table1 

使用 id 的结果集和

Select * from table2 where id in (resultset) 

如何使用 Nodejs 和 MySQL 实现它。我是 Nodejs express 框架的初学者。

【问题讨论】:

    标签: mysql node.js express asynchronous async-await


    【解决方案1】:

    你可以使用字符串连接:

    const query1 = "Select id from table1";
    
    const query2 = `Select * from table2 where id in (${query1})`
    

    或者只写嵌套查询:

    const query = "Select * from table2 where id in (Select id from table1)"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-30
      • 2023-03-28
      • 2019-03-09
      • 2020-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多