Node.js MySQL FIELD() Function Last Updated : 17 Feb, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report FIELD() function is a built-in function in MySQL that is used to get the position of the first occurrence of a value in a set of expressions. In the case of string values, it is not case-sensitive. Syntax: FIELD(value, input_1, input_2, input_3, ...)Parameters: It takes two parameters as follows: value: It is the given value to be searched.input: It is the inputs that are checked for equality against the given value.Return Value: It returns the position of the first occurrence of a value in a set of expressions. If nothing found then it will return 0. Module Installation: Install the mysql module using the following command: npm install mysql Database: Our SQL publishers table preview with sample data is shown below: Example 1: index.js const mysql = require("mysql"); let db_con = mysql.createConnection({ host: "localhost", user: "root", password: '', database: 'gfg_db' }); db_con.connect((err) => { if (err) { console.log("Database Connection Failed !!!", err); return; } console.log("We are connected to gfg_db database"); // Here is the query let query = "SELECT FIELD(2, 12, 15, 2, 122) AS Output"; db_con.query(query, (err, rows) => { if(err) throw err; console.log(rows); }); }); Run the index.js file using the following command: node index.jsOutput: Example 2: index.js const mysql = require("mysql"); let db_con = mysql.createConnection({ host: "localhost", user: "root", password: '', database: 'gfg_db' }); db_con.connect((err) => { if (err) { console.log("Database Connection Failed !!!", err); return; } console.log("We are connected to gfg_db database"); // Here is the query let query = "SELECT FIELD('geek', 'Geeek', 'gEEK', 'geeK') AS Output"; db_con.query(query, (err, rows) => { if(err) throw err; console.log(rows); }); }); Run the index.js file using the following command: node index.jsOutput: Comment More infoAdvertise with us Next Article Node.js MySQL FIELD() Function P pratikraut0000 Follow Improve Article Tags : Technical Scripter Web Technologies Node.js Technical Scripter 2020 NodeJS-MySQL +1 More Similar Reads Node.js MySQL AVG() Function We use AVG Function to get the average value of all rows in the given column of MySQL Table. Syntax: AVG([column_name]) Parameters: AVG() function accepts a single parameter as mentioned above and described below. column_name: Columnâs name from which we have to return the average value. Module Inst 2 min read Node.js MySQL FORMAT() Function FORMAT() function is a built-in function in MySQL that is used to format input numbers in the format of ...**, ***, *** also, round float numbers to a specific number of decimal places. Syntax: FORMAT(number, number_of_decimal_places)Parameters: It takes two parameters as follows: number: The number 2 min read Node.js MySQL FIND_IN_SET() Function FIND_IN_SET() function is a built-in function in MySQL that is used to get the position of the first occurrence of value string in a list of strings separated by comma(','). Syntax: FIND_IN_SET(value, list_of_string)Parameters: It takes two parameters as follows: value: It is the value to be searche 2 min read Node.js MySQL Count() Function We use the COUNT() function in MySQL to count a number of rows in a column satisfying the WHERE clause. Syntax: COUNT([column_name]) Parameters: COUNT() function accepts a single parameter as mentioned above and described below. column_name: Columnâs name from which we have to return the count value 2 min read FIELD() function in MySQL FIELD() : This function helps in returning the position of a value in the given value list. If the user passes string values as the argument of FIELD() function, then the search will be performed as string values. And, If the user passes numeric values as the argument of FIELD() function, then searc 2 min read Like