
- 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
Create an aggregate checksum of a column in MySQL
You can use CRC32 checksum for this. The syntax is as follows −
SELECT SUM(CRC32(yourColumnName)) AS anyAliasName FROM yourTableName;
To understand the above syntax, let us create a table. The query to create a table is as follows −
mysql> create table CRC32Demo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> UserId varchar(20) -> ); Query OK, 0 rows affected (0.67 sec)
Insert some records in the table using insert command. The query is as follows −
mysql> insert into CRC32Demo(UserId) values('USER-1'); Query OK, 1 row affected (0.38 sec) mysql> insert into CRC32Demo(UserId) values('USER-123'); Query OK, 1 row affected (0.15 sec) mysql> insert into CRC32Demo(UserId) values('USER-333'); Query OK, 1 row affected (0.13 sec)
Display all records from the table using a select statement. The query is as follows −
mysql> select *from CRC32Demo;
Output
+----+----------+ | Id | UserId | +----+----------+ | 1 | USER-1 | | 2 | USER-123 | | 3 | USER-333 | +----+----------+ 3 rows in set (0.00 sec)
Here is the query to create an aggregate checksum of a column −
mysql> select sum(crc32( UserId)) from CRC32Demo;
Output
+---------------------+ | sum(crc32( UserId)) | +---------------------+ | 3142885447 | +---------------------+ 1 row in set (0.00 sec)
- Related Articles
- Get the maximum value of a column with MySQL Aggregate function
- Find the average of column values in MySQL using aggregate function
- How to add column values in MySQL without using aggregate function?
- Calculate an MD5 Checksum of a Directory in Linux
- How to create and fill a new column in an already created MySQL table?
- How to create a Cumulative Sum Column in MySQL?
- How to create NVARCHAR column in MySQL?
- Create a MySQL function and find the average of values in a column
- Create MySQL column with Key=MUL?
- Create a quartile column for each value in an R data frame column.
- Calculation of TCP Checksum
- MySQL concat() to create column names to be used in a query?
- Fletcher’s Checksum
- Call aggregate function in sort order with MySQL
- How to create a column with the serial number of values in character column of an R data frame?

Advertisements