
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
MySQL get hash value for each row?
Get hash value of each row using MD5() function from MySQL. The syntax is as follows −
SELECT MD5(CONCAT(yourColumnName1,yourColumnName2,yourColumnName3,.......N)) as anyVariableName FROM yourTableName;
To understand the above syntax, let us create a table. The query to create a table is as follows −
mysql> create table getHashValueForEachRow -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Name varchar(20), -> Age int, -> Marks int, -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (1.25 sec)
Insert records in the table using insert command. The query is as follows −
mysql> insert into getHashValueForEachRow(Name,Age,Marks) values('Larry',24,89); Query OK, 1 row affected (0.22 sec) mysql> insert into getHashValueForEachRow(Name,Age,Marks) values('David',26,98); Query OK, 1 row affected (0.24 sec) mysql> insert into getHashValueForEachRow(Name,Age,Marks) values('Bob',21,67); Query OK, 1 row affected (0.20 sec) mysql> insert into getHashValueForEachRow(Name,Age,Marks) values('Sam',22,56); Query OK, 1 row affected (0.22 sec) mysql> insert into getHashValueForEachRow(Name,Age,Marks) values('Mike',25,80); Query OK, 1 row affected (0.72 sec)
Display all records from the table using select statement. The query is as follows −
mysql> select *from getHashValueForEachRow;
The following is the output −
+----+-------+------+-------+ | Id | Name | Age | Marks | +----+-------+------+-------+ | 1 | Larry | 24 | 89 | | 2 | David | 26 | 98 | | 3 | Bob | 21 | 67 | | 4 | Sam | 22 | 56 | | 5 | Mike 25 | 80 | | +----+-------+------+-------+ 5 rows in set (0.00 sec)
The following is the query to get hash value of each row −
mysql> select md5(concat(Id,Name,Age,Marks)) as HashValueOfEachRow from getHashValueForEachRow;
Here is the output −
+----------------------------------+ | HashValueOfEachRow | +----------------------------------+ | a5f6b8e1a701d467cf1b4d141027ca27 | | 6e649522c773b6a6672e625939eb4225 | | 8bd419e9b7e9e014a4dc0596d70e93c8 | | 504cf50194a2a6e3481dfa9b8568b9e6 | | 08716a8dad7105a00c49ea30d278b315 | +----------------------------------+ 5 rows in set (0.00 sec)
- Related Articles
- Get only a single value from a specific MySQL row?
- Get Hash Code for Integer in Java
- Count the same value of each row in a MySQL column?
- How does ‘FOR EACH ROW’ work in the MySQL trigger?
- How to set default value for empty row in MySQL?
- Checking for Key/Value Existence in Perl Hash
- Get the hash code for this instance in C#
- How can a query multiply 2 cells for each row in MySQL?
- MySQL row declarations for ZF?
- Find the column index of least value for each row of an R matrix
- Find the column number with largest value for each row in an R matrix.
- Get row data for the lowest and highest values in a MySQL column
- Select the maximum for each value in a MySQL table?
- In MySQL, how we can get the total value by category in one output row?
- Get the hash code for the current Int64 instance in C#

Advertisements