node-mysql 仅在合并两个 table 后给出第一个 table 的数据

node-mysql only giving data from first table after union of two tables

我有两个 tables toponlinestoresbrands 当 运行 MySQL WorkBench 中的查询(下面列出)时,它们工作正常但使用 node-mysql 我只从第一个 table

获取数据
set @toponlinestores=3;
set @brands=2;
SELECT * from (
SELECT 
'toponlinestores' as 'table_name',store_name,tl.id as website_id, 
@toponlinestores * (MATCH(store_name) AGAINST ('f*' IN BOOLEAN MODE)) as     relevance
from toponlinestores tl
UNION
SELECT 
'brands' as 'table_name',brand_name,
br.id as brand_id,
@brands * (MATCH(brand_name) AGAINST ('f*' IN BOOLEAN MODE)) as relevance
from brands br
)
as sitewide WHERE relevance > 0;

**result :
1.  toponlinestores flipkart    2   3.051822781562805
2.  brands          fossil_mini 18  1.6311430931091309**

但是当我使用 node-mysql

var sql1 = 'set @toponlinestores=3';
    var sql2 = '@brands=2';
    var sql3 = "SELECT * from ("+
    "SELECT "+
      " 'toponlinestores' as 'table_name',store_name as name,id as id, "+
      " @toponlinestores * (MATCH(store_name) AGAINST ('f*' IN BOOLEAN MODE)) as relevance"+
      " from toponlinestores "+
    " UNION "+
    "SELECT "+
     " 'brands' as 'table_name',brand_name as name, " +
      "id as id, " +
      " @brands * (MATCH(brand_name) AGAINST ('f*' IN BOOLEAN MODE)) as relevance "+
               " from brands"+
  ")"+
  "as sitewide WHERE relevance > 0";


  var query1 = connection.query(sql1);
    query1.on("error", function (err) {
        // handle error
    });
    query1.on("end", function () {
      var query2 = connection.query(sql2);
      query2.on("error", function (err) {
          // handle error
      });
      query2.on("end", function () {
        connection.query(sql3,function(err,res_data)
        {
                 if(err) console.log(err);
                 else
                 {
                  res.json(res_data);
                  console.log(res_data);
                 }

        });

      });
  });

结果是: 1. toponlinestores flipkart 2 3.051822781562805

我没有从第二个 table 中获取数据,但是当我在 MySQL 中执行相同的查询时 WorkBench 我正在获取数据来自两个tables。

请帮忙 - 提前致谢。

试试这个:-

var sql2 = 'set @brands=2';

代替

var sql2 = '@brands=2';