HI WELCOME TO SIRIS

Node.js MySQL SELECT Unique Record (WHERE Clause)

Leave a Comment
Retrieve a unique data from the table "employees".
Create a js file named selectwhere.js having the following data in DBexample folder.
  1. var mysql = require('mysql');  
  2. var con = mysql.createConnection({  
  3. host: "localhost",  
  4. user: "root",  
  5. password: "12345",  
  6. database: "javatpoint"  
  7. });  
  8. con.connect(function(err) {  
  9. if (err) throw err;  
  10. con.query("SELECT * FROM employees WHERE id = '1'", function (err, result) {  
  11. if (err) throw err;  
  12. console.log(result);  
  13. });  
  14. });  
Now open command terminal and run the following command:
  1. Node selectwhere.js  
Node.js unique record 1

Node.js MySQL Select Wildcard

Retrieve a unique data by using wildcard from the table "employees".
Create a js file named selectwildcard.js having the following data in DBexample folder.
  1. var mysql = require('mysql');  
  2. var con = mysql.createConnection({  
  3. host: "localhost",  
  4. user: "root",  
  5. password: "12345",  
  6. database: "javatpoint"  
  7. });  
  8. con.connect(function(err) {  
  9. if (err) throw err;  
  10. con.query("SELECT * FROM employees WHERE city LIKE 'A%'", function (err, result) {  
  11. if (err) throw err;  
  12. console.log(result);  
  13. });  
  14. });  
Now open command terminal and run the following command:
  1. Node selectwildcard.js  
It will retrieve the record where city start with A.
Node.js unique record 2

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.