Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6992951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:42:05+00:00 2026-05-27T19:42:05+00:00

I’m using felixge’s node-mysql plugin for Node.js. I want to find the highest ID

  • 0

I’m using felixge’s node-mysql plugin for Node.js. I want to find the highest ID in my database, so I use:

client.query(
"SELECT MAX('hits_total') FROM " + TABLE,
function (err, results, fields) {
    if(err) {
        throw err;
    }
    console.log(results);
    console.log(fields);
}

);

But how do I find the value of the result? The console logs:

    { 'MAX(\'hits_total\')': 
   { length: 39,
     received: 39,
     number: 2,
     type: 4,
     catalog: 'def',
     name: 'MAX(\'hits_total\')',
     charsetNumber: 192,
     fieldLength: 30,
     fieldType: 253,
     flags: 0,
     decimals: 31 } }
{"MAX('hits_total')":"hits_total"}

So I get one result, however I can not find it’s value (which is 633 in this case).

If anyone can help me or point me in the right direction, that would be great 😀


edit

Ok, so I’ve done some more testing and it seems that there is something wrong with the syntax "SELECT MAX('hits_total') FROM " + TABLE,

I can tell because when I change it to, for instance:

"SELECT * FROM " + TABLE + " WHERE id=200"

it suddenly returns a valid object:

{ id: 200, hits_total: 102 }

So maybe MAX(‘whatever_field’) isn’t supported yet? How can I find out, and are there alternatives to achieve the same effect?


another edit > I can’t answer my own question within 8 hours, so here it is:

Right, I’ve found a solution.

Like mentioned, the syntax ("SELECT MAX('hits_total') FROM " + TABLE for some reason doesn’t return a useful object.

So instead, I use this syntax (I’ll paste the entire block for completeness):

var hits = 0;
var query = client.query("SELECT * FROM hits ORDER BY hits_total DESC LIMIT 1");
query
    .on('row', function(row) {
        console.log("(row)");
        hits = row.hits_total;
    })
    .on('end', function(result) {
        console.log("(end)");
    });

The row object returned by query.on('row', callback(row){}); has the fieldname(s) of that row as properties – in this case .hits_total.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:42:06+00:00Added an answer on May 27, 2026 at 7:42 pm

    results should be an array if it is actually returning the rows. In this case it looks like it is returning something else instead.

    The issue is with your query, not with your code. You have single-quotes around “hits_total”, so it is literally taking the maximum of a string. Remove the single quotes, or change them to back-ticks, and then it will process the string as a column name.

    client.query("SELECT MAX(hits_total) FROM " + TABLE, function (err, results, fields) {
      if (err) {
        throw err;
      }
      console.log(results);
      console.log(fields);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.