Express/MySQL not returning same value returned by

2019-08-02 06:23发布

I have a query that is perfectly working when I run it on MySQL Workbench, but when I run it on Express it is returning me all the data on my database. Please help fix?
PS. posted this before but didn't get fixed.

--Client

$.ajax({
   url: '/filter',
   type: 'get',
   contentType: 'application',
   data: { categoryIDs : checkedCategory,
           materialIDs : checkedMaterial,
           designIDs   : checkedDesign},
   success: function(response) {
      console.log(response.products);
   }
});

--Server code

getFilteredTable: function(req, res, next) {
   var filter="SELECT COUNT(A.id) \
               FROM tbl_product A JOIN tbl_product_details B ON A.id = B.prod_id  \
               JOIN tbl_category C ON A.id = C.prod_id \
               JOIN tbl_material D ON A.id = D.prod_id \
               JOIN tbl_design E ON A.id = E.prod_id \
               WHERE C.category_id IN (?) \
               AND (D.material_id IN (?) \
               OR E.design_id IN (?))";
   mysqlConnection.query(filter, [req.query.categoryIDs, req.query.materialIDs, req.query.designIDs], function(err, rows, fields) {
      if(!err)
      res.send({products : rows});
      else
      console.log(err);
   });
},

This is my query:

SELECT COUNT(A.id)
FROM tbl_product A 
JOIN tbl_product_details B ON A.id = B.prod_id
JOIN tbl_category C ON A.id = C.prod_id
JOIN tbl_material D ON A.id = D.prod_id
JOIN tbl_design E ON A.id = E.prod_id
WHERE C.category_id IN (6) AND (D.material_id IN (15) OR E.design_id IN (39));

I expect the output to be (workbench result):
COUNT(A.id): 42

instead, it's giving me:
COUNT(A.id): 1582

0条回答
登录 后发表回答