1
app.get("/total", function(req,res){
var q = "SELECT COUNT(*) AS new FROM voters_detail WHERE parties LIKE '%BJP%'";
connection.query(q, function(err, results){
    if(err) throw err;
    var hello = results[0].new;
    res.send("BJP Was Voted By " + hello + " People");
});

});

I want to add and new query which says that;

SELECT COUNT(*) FROM voters_detail WHERE parties LIKE '%Congress';

And then I want that it also displays on the \total page when I call this route on my server.

Help me out, please!

newBee
  • 1,289
  • 1
  • 14
  • 31
  • I think your actual problem is more related to SQL rather than Node.js: "How to make two select statements in one query". An answer can be found e.g. here: https://stackoverflow.com/questions/31979008/sql-two-select-statements-in-one-query . – newBee Feb 11 '20 at 12:51
  • 1
    What exactly keeps you from performing a second query? – Nico Haase Feb 11 '20 at 13:52
  • No, the solution which you provides says that how to select 2 queries from 2 different tables at once. But I want to select 2 queries means I want to show on the server that ........ people voted this party and ....... people voted this party but this is not running. @newBee – Devanshu Kumar Feb 11 '20 at 18:30
  • There is no difference wether or not you do two selects from two tables or from just one: `SELECT 'bjp' as party, COUNT(*) AS cnt FROM voters_detail WHERE parties LIKE '%BJP%' UNION ALL SELECT 'congress' as party, COUNT(*) AS cnt FROM voters_detail WHERE parties LIKE '%Congress';` – newBee Feb 12 '20 at 10:25
  • @newBee pls see the answer section of this question, I have pasted what I have tried. Help pls! – Devanshu Kumar Feb 12 '20 at 12:37
  • please update your question by APPENDING it to your original question. Do not, however, replace what you have already written. Otherwise it will be very hard for anyone to understand the answers/comments so far. – newBee Feb 13 '20 at 08:07

1 Answers1

-1

I guess you should make a file of xyz.sql and then write the two queries in that file and then parse it to the code.