Skip to content
  • SiteMap
  • Our Services
  • Frequently Asked Questions (FAQ)
  • Support
  • About Us

UpdateGadh

Update Your Skills.

  • Home
  • Projects
    •  Blockchain projects
    • Python Project
    • Data Science
    •  Ai projects
    • Machine Learning
    • PHP Project
    • React Projects
    • Java Project
    • SpringBoot
    • JSP Projects
    • Java Script Projects
    • Code Snippet
    • Free Projects
  • Tutorials
    • Ai
    • Machine Learning
    • Advance Python
    • Advance SQL
    • DBMS Tutorial
    • Data Analyst
    • Deep Learning Tutorial
    • Data Science
    • Nodejs Tutorial
  • Blog
  • Contact us
  • Toggle search form
Node.js MySQL SELECT Unique Record

Node.js MySQL SELECT Unique Record (WHERE Clause)

Posted on October 24, 2025October 24, 2025 By Rishabh saini No Comments on Node.js MySQL SELECT Unique Record (WHERE Clause)

Node.js MySQL SELECT Unique Record

In this tutorial, we’ll learn how to retrieve specific or unique records from a MySQL table using Node.js. This is particularly useful when you want to fetch data based on certain conditions, such as employee ID, name, or location. We’ll also explore how to use wildcards in SQL queries to fetch records that match a particular pattern.

Data Science Tutorial:–Click Here

1. Retrieving a Unique Record Using WHERE Clause

To begin, let’s create a JavaScript file named selectwhere.js inside a folder called DBexample. This script will connect Node.js to a MySQL database and retrieve a unique record from the employees table based on a specific ID.

Here’s the code:

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

con.connect(function(err) {  
  if (err) throw err;  
  con.query("SELECT * FROM employees WHERE id = '1'", function (err, result) {  
    if (err) throw err;  
    console.log(result);  
  });  
});  

Explanation:

Introduction to Applied AI:–Click Here

  • We first import the MySQL module using require('mysql').
  • Then, we create a connection to the database updategadh using mysql.createConnection().
  • Inside the connect() method, we check for errors and execute a SQL query: SELECT * FROM employees WHERE id = '1' This query retrieves the record from the employees table where the id is equal to 1.
  • The result is displayed in the console using console.log(result).

To execute this file, open your command terminal, navigate to the DBexample folder, and run:

node selectwhere.js

This will display the unique employee record with id = 1 in the console.

Download New Real Time Projects :–Click here

2. Retrieving Records Using Wildcard (LIKE Operator)

Now, let’s see how to use wildcards to filter records dynamically based on a pattern.
Create another file named selectwildcard.js in the same DBexample folder.

Here’s the code:

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

con.connect(function(err) {  
  if (err) throw err;  
  con.query("SELECT * FROM employees WHERE city LIKE 'A%'", function (err, result) {  
    if (err) throw err;  
    console.log(result);  
  });  
});  

Explanation:

SQL Tutorial :–Click Here

  • The LIKE operator in SQL is used for pattern matching.
  • Here, the query: SELECT * FROM employees WHERE city LIKE 'A%' retrieves all employee records where the city name starts with the letter ‘A’.
  • The % symbol acts as a wildcard representing any number of characters following ‘A’.

To run the script, execute the following command in the terminal:

node selectwildcard.js

This will fetch and display all employee records where the city name begins with A.

Summary

By following this guide, you’ve learned how to use Node.js with MySQL to:

  • Connect to a database.
  • Retrieve specific records using the WHERE clause.
  • Use the LIKE operator and wildcard characters to perform flexible searches.

These methods form the foundation for building more advanced database-driven applications with Node.js and MySQL.

Deep Learning Tutorial:– Click Here
Machine Learning Tutorial:–Click Here
Complete Advance AI topics:- CLICK HERE
Complete Python Course with Advance topics:-Click Here


mysql select unique values from multiple columns select unique sql mysql select without duplicates mysql show unique constraints which mysql keyword is used to sort the result set distinct rows in mysql select unique email mysql mysql count unique mysql select query nodejs, nodejs mysql select, nodejs mysql delete a record, select mysql count value in nodejs, node.js mysql select query example, node js mysql select data, nodejs mysql query, nodejs mysql order by, mysql order byquery nodejs, nodejs mysql pool query, nodejs delete dabase record, nodejs express mysql, nodejs mysql tutorial, nodejs mysql connection pool, mysql update query nodejs, nodejs and mysql tutorials, records mysql, nodejs mysql2, nodejs mysql crud, nodejs + mysql

    Post Views: 247
    Node.js Tutorial Tags:mysql order byquery nodejs, mysql select query nodejs, mysql update query nodejs, node js mysql select data, node.js mysql select query example, nodejs and mysql tutorials, nodejs delete dabase record, nodejs express mysql, nodejs mysql connection pool, nodejs mysql crud, nodejs mysql delete a record, nodejs mysql order by, nodejs mysql pool query, nodejs mysql query, nodejs mysql select, nodejs mysql tutorial, nodejs mysql2, records mysql, select mysql count value in nodejs

    Post navigation

    Previous Post: Best Task Management System — Built Using MERN Stack
    Next Post: Best College Management System — Built Using MERN Stack

    More Related Articles

    Node.js vs Java Node.js vs Java – Python Project with Source Code Node.js Tutorial
    NestJS NestJS Node.js Tutorial
    Node.js BuffersNode.js Buffers Node.js Buffers Node.js Tutorial

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    You may also like

    1. Install Nodejs on Windows
    2. Node.js Command Line Options
    3. Node.js Assertion Testing
    4. Node.js MySQL Update Records
    5. Node.js Create Connection with MongoDB
    6. Node.js MongoDB Filter Query

    Most Viewed Posts

    1. Top Large Language Models in 2025
    2. Online Shopping System using PHP, MySQL with Free Source Code
    3. login form in php and mysql , Step-by-Step with Free Source Code
    4. Flipkart Clone using PHP And MYSQL Free Source Code
    5. News Portal Project in PHP and MySql Free Source Code
    6. User Login & Registration System Using PHP and MySQL Free Code
    7. Top 10 Final Year Project Ideas in Python
    8. Online Bike Rental Management System Using PHP and MySQL
    9. E learning Website in php with Free source code
    10. E-Commerce Website Project in Java Servlets (JSP)
    • AI
    • ASP.NET
    • Blockchain
    • ChatCPT
    • code Snippets
    • Collage Projects
    • Data Science Project
    • Data Science Tutorial
    • DBMS Tutorial
    • Deep Learning Tutorial
    • Final Year Projects
    • Free Projects
    • How to
    • html
    • Interview Question
    • Java Notes
    • Java Project
    • Java Script Notes
    • JAVASCRIPT
    • Javascript Project
    • JSP JAVA(J2EE)
    • Machine Learning Project
    • Machine Learning Tutorial
    • MySQL Tutorial
    • Node.js Tutorial
    • PHP Project
    • Portfolio
    • Python
    • Python Interview Question
    • Python Projects
    • PythonFreeProject
    • React Free Project
    • React Projects
    • Spring boot
    • SQL Tutorial
    • TOP 10
    • Uncategorized
    • Online Examination System in PHP with Source Code
    • AI Chatbot for College and Hospital
    • Job Portal Web Application in PHP MySQL
    • Online Tutorial Portal Site in PHP MySQL — Full Project with Source Code
    • Online Job Portal System in JSP Servlet MySQL

    Most Viewed Posts

    • Top Large Language Models in 2025 (8,613)
    • Online Shopping System using PHP, MySQL with Free Source Code (5,215)
    • login form in php and mysql , Step-by-Step with Free Source Code (4,867)

    Copyright © 2026 UpdateGadh.

    Powered by PressBook Green WordPress theme