3

I have a query that works perfectly in PHPMyAdmin:

SET @row_number=0; 
SELECT * FROM blah blah @row_number blah blah;

However, when I put this into Node.JS, I can't use a simple con.query("SET @row_number=0; SELECT * FROM blah blah @row_number blah blah;") because there's technically 2 queries there. So I tried doing:

con.query("SET @row_number=0")
con.query("SELECT * FROM blah blah @row_number blah blah")

However, this treats it as if the first query isn't even there. How can I combine these queries into one query? Or, is there any other workaround?

  • Are you trying to [generate a row number column](https://stackoverflow.com/questions/3126972)? Otherwise, take a look at [this](https://stackoverflow.com/questions/23266854). – zanlok Mar 17 '18 at 00:46
  • I am trying to do that, however, from that link, I made the query `SELECT * FROM (SELECT serverusers.serverID, serverusers.userID, serverusers.xpTotal, users.bot @curRow := @curRow + 1 AS row_number FROM users INNER JOIN serverusers ON users.userID = serverusers.userID WHERE users.bot = 'false' && serverID = 318467989655781389 ORDER BY xpTotal DESC) AS t WHERE t.userID = 289233475481894914 JOIN (SELECT @curRow := 0) r);` Have I done something wrong? Because there's a syntax error near '@curRow := @curRow + 1 AS row_number FROM users INNER JOIN serverusers ON users.' –  Mar 17 '18 at 01:28

1 Answers1

3

Try this for node-mysql:

var connection = mysql.createConnection({multipleStatements: true});

(taken from this answer)

zanlok
  • 1,608
  • 1
  • 16
  • 29
  • Im using the `mysql` library not the `node-mysql` library. Will it still work? –  Mar 17 '18 at 01:19