Node.js Tutorial – Select Record from MySQL Table

The tutorial provides the node.js integration with MySQL for selecting record from the mysql table. The tutorial provides the steps on how to select record from mysql table using node.js application .

Node.js Delete Record from MySQL Table

The MySQL uses ‘SELECT * FROM’ statement for selecting records into mysql table. Ensure that you have the mysql table with records before proceeding with the record selection process. The WHERE Clause and Order by clause can also be used in the SQL Query which is given as an example below.

var mysql = require('mysql');  
var con = mysql.createConnection({  
  host: "localhost",  
  user: "root",  
  password: ""  ,
  database: "oracleappshelpDB"
});

con.connect(function(err) {
  if (err) throw err;
  con.query("SELECT * FROM oracleappshelpusers order by firstName",  function (err, result) {
    if (err) throw err;
    console.log(result);
  });
});
var mysql = require('mysql');  
var con = mysql.createConnection({  
  host: "localhost",  
  user: "root",  
  password: ""  ,
  database: "oracleappshelpDB"
});

con.connect(function(err) {
  if (err) throw err;
  con.query("SELECT * FROM oracleappshelpusers where firstName ='Mohit'",  function (err, result) {
    if (err) throw err;
    console.log(result);
  });
});
var mysql = require('mysql');  
var con = mysql.createConnection({  
  host: "localhost",  
  user: "root",  
  password: ""  ,
  database: "oracleappshelpDB"
});

con.connect(function(err) {
  if (err) throw err;
  con.query("SELECT * FROM oracleappshelpusers order by firstName",  function (err, result) {
    if (err) throw err;
    console.log(result);
  });
});