SQL Tutorial - How to compare multiple columns in SQL
Learn how to compare multiple columns in SQL, in this video I cover comparing multiple columns in the WHERE clause, using CHECKSUM, BINARY_CHECKSUM and HASHBYTES. I also discuss the advantages and disadvantages of using CHECKSUM, BINARY_CHECKSUM and HASHBYTES and what is my preferred approach for comparing multiple columns.
An important point when using CHECKSUM, BINARY_CHECKSUM or HASHBYTES to compare multiple columns is that the column list show always be in the same order to get an accurate comparison. When using the HASHBYTES function, always add a separator that does not exist in the data such as a pipe.
If you would like more detail on the functions used in this video to compare multiple columns in SQL then take a look at the links below:
The SQL queries used in this video are available below:
DROP TABLE [dbo].[CustomerStaging];
CREATE TABLE [dbo].[CustomerStaging]
(
[SourceKey] [int] NULL,
[Title] [varchar](10) NULL,
[FirstName] [varchar](50) NULL,
[MiddleName] [varchar](50) NULL,
[LastName] [varchar](50) NULL,
[DOB] [date] NULL,
[AddressLine1] [varchar](50) NULL,
[AddressLine2] [varchar](50) NULL,
[City] [varchar](50) NULL,
[PostCode] [varchar](10) NULL
);
INSERT INTO (SourceKey, Title, FirstName, MiddleName, LastName, DOB, AddressLine1, AddressLine2, City, PostCode)
VALUES
(1000, ’Mrs’, ’Deborah’, NULL, ’Wilkinson’, ’19960513’, ’1 The Barns’, NULL, ’London’, ’NE1 1RS’),
(2000, ’Dr’, ’Siobhan’, ’Mary’, ’Jones’, ’19840822’, ’Portobello House’, ’Yarn Street’, ’Birmingham’, ’B16 1PZ’),
(3000, ’Mr’, ’Karl’, NULL, ’Smith’, ’19790906’, ’5 Main Street’, NULL, ’Manchester’, ’M1 1PQ’);
DROP TABLE [dbo].[Customer];
CREATE TABLE [dbo].[Customer]
(
[CustomerKey] [int] NOT NULL IDENTITY(1, 1),
[SourceKey] [int] NULL,
[Title] [varchar](10) NULL,
[FirstName] [varchar](50) NULL,
[MiddleName] [varchar](50) NULL,
[LastName] [varchar](50) NULL,
[DOB] [date] NULL,
[AddressLine1] [varchar](50) NULL,
[AddressLine2] [varchar](50) NULL,
[City] [varchar](50) NULL,
[PostCode] [varchar](10) NULL
);
INSERT INTO (SourceKey, Title, FirstName, MiddleName, LastName, DOB, AddressLine1, AddressLine2, City, PostCode)
VALUES
(1000, ’Miss’, ’Deborah’, NULL, ’Austin’, ’19960513’, ’1 The Barns’, NULL, ’London’, ’NE1 1RS’),
(2000, ’Dr’, ’Siobhan’, ’Mary’, ’Jones’, ’19840822’, ’Portobello House’, ’Yarn Street’, ’Birmingham’, ’B16 1PZ’),
(3000, ’Mr’, ’Karl’, NULL, ’Smith’, ’19790906’, ’250 Wood Road’, NULL, ’Manchester’, ’M25 1HH’);
-- CHECKSUM
SELECT
*
FROM AS A
LEFT OUTER JOIN AS B
ON =
WHERE
CHECKSUM(
,
,
,
,
,
,
,
,
)
[replace with not equal to]
CHECKSUM(
,
,
,
,
,
,
,
,
)
-- BINARY_CHECKSUM
SELECT
*
FROM AS A
LEFT OUTER JOIN AS B
ON =
WHERE
BINARY_CHECKSUM(
,
,
,
,
,
,
,
,
)
[replace with not equal to]
BINARY_CHECKSUM(
,
,
,
,
,
,
,
,
)
-- HASHBYTES
SELECT
*
FROM AS A
LEFT OUTER JOIN AS B
ON =
WHERE
HASHBYTES(’SHA2_512’,
CONCAT(
,
,
,
,
,
,
,
,
)
)
[replace with not equal to]
HASHBYTES(’SHA2_512’,
CONCAT(
,
,
,
,
,
,
,
,
)
)
4 views
1057
309
2 months ago 00:13:02 1
Как создать таблицу в бд / Как работают таблицы SQL [Базы данных для C# программиста] #2
3 months ago 04:26:52 1
Learn Python - Full Course for Beginners [Tutorial]
3 months ago 00:04:22 1
Laravel Data SQL Update: Migrations or One-Time Package?
3 months ago 01:07:50 1
Учим Базы Данных за 1 час! #От Профессионала
4 months ago 00:08:28 7
Лучшие бесплатные курсы и книги по Python в 2024 год.
4 months ago 06:42:29 1
Python App Development: Build Modern GUIs in 7 Hours (Beginners Course)
4 months ago 19:23:46 1
Data Analyst Bootcamp for Beginners (SQL, Tableau, Power BI, Python, Excel, Pandas, Projects, more)
4 months ago 04:22:13 1
Data Analysis with Python - Full Course for Beginners (Numpy, Pandas, Matplotlib, Seaborn)
4 months ago 00:04:59 13
Allen & Heath SQ Compression Tutorial
4 months ago 00:26:16 1
C++ Introduction | C ++ Tutorial | Mr. Kishore
4 months ago 01:06:23 1
Energy power meters 3 units connect wtih WinCC Explorer SCADA Server and Client configuration
4 months ago 00:08:40 1
Tutorial Setup Emulator Cabal Online (Breaklee)
5 months ago 00:03:35 6
C++ Лучшие бесплатные курсы и книги 2024!
5 months ago 00:25:44 1
Structures in C | C Language Tutorial
5 months ago 00:11:51 1
Introduction to Pointers | C Language Tutorial
5 months ago 00:24:21 1
How to Install Oracle 19c and SQL Developer on windows 10/11 [ 2023 Update ] Complete guide
5 months ago 01:08:11 1
Core MVC CRUD Operations using .NET 8 and Entity Framework Core - MVC For Beginners Tutorial
5 months ago 00:20:44 1
Как собрать Скваер-0 | | How to Solve the Square-0 | SQ-0 Tutorial
6 months ago 01:15:36 1
How to Create Hotel Management System in C# with SQLite Database - Full Tutorial
6 months ago 00:27:02 9
How To Migrate ZABBIX from MySQL to PostgreSQL
6 months ago 00:51:43 1
Туториал по базе данных на демонстрационный экзамен 2023 по правилам WorldSkills в колледжах
6 months ago 00:08:30 1
Как собрать Зеркальный Скваер-0 | | How to Solve the Mirror Square-0 | SQ-0 Tutorial
6 months ago 00:14:06 2
How to Connect to PostgreSQL with EF Core: A Step-by-Step Guide
6 months ago 02:49:35 1
Inventory Management System(C# Full Project using SQL server with source code)