## Use ROW_NUMBER to Create a Unique ID

Learn how to use the ROW_NUMBER() windows function to generate a unique ID. Problem: You have a table named Teams with information

Use ROW_NUMBER to Create a Unique ID

## Compare Two Moving Averages in SQL

Problem We want to compare two moving averages in SQL. We’ll use window functions to do this, as it is easier write

Compare Two Moving Averages in SQL

## Find and Remove Duplicates in SQL

Problem You want to remove duplicates in SQL. You know it is easy to find duplicates using GROUP BY, but how do

Find and Remove Duplicates in SQL

## How to Find Duplicates using a Windows Function?

Problem You need to find duplicates and then identify the records by their primary keys. Background Here’s an example of how to

How to Find Duplicates using a Windows Function?

## Calculate a Moving Average in SQL using A Windows Function

Problem How do you create a moving average using windows functions in SQL? Background There is no built-in function to create a

Calculate a Moving Average in SQL using A Windows Function

## Calculate a Running Total in SQL using a Windows Function

Problem How do you create a running total on a column using SQL? Background There is no built-in function to create a

Calculate a Running Total in SQL using a Windows Function

## Working with ROW_NUMBER, RANK, and DENSE_RANK

Introduction Window functions are an essential tool for data analysis, particularly in the SQL language. They allow you to perform complex calculations,

Working with ROW_NUMBER, RANK, and DENSE_RANK

## Window Functions vs Group By Queries?

In this article let’s look at window functions vs GROUP BY queries. We’ll do so by looking at how each statement works

Window Functions vs Group By Queries?

## CREATE VIEW Side Effects

So what happens when you create a view, and then later someone else changes the underlying tables? In this article let’s explore

CREATE VIEW Side Effects

## Concatenate Text with SQL and how to protect from NULL.

In this article I’ll show you three ways you can use SQL to concatenate columns into a single expression.  You’ll see as

Concatenate Text with SQL and how to protect from NULL.

## SQL Server Inserting Multiple Rows

Problem Statement Getting data loaded into your SQL Server tables can come in a variety of methods. There are many mechanisms that

SQL Server Inserting Multiple Rows

## How to Round Up to Nearest Integer

Problem You want to round up to the nearest integer. Background Suppose you have a list of final sales amount that you

How to Round Up to Nearest Integer

## Calculate Moving Median in SQL

Recently a student asked me how he could calculate a Moving Median.  It’s not as easy as you think, as SQL doesn’t

Calculate Moving Median in SQL

## Use SQL to Find the MEDIAN

Problem You need use SQL to calculate the Median of a result from SQL Server. Background Suppose you need to calculate the

Use SQL to Find the MEDIAN

## How to Avoid SQL Divide by Zero

Problem You need to avoid SQL divide by zero errors. Suppose you need to calculate velocity using the formula v = s

How to Avoid SQL Divide by Zero

## How to Subtract 30 Days from a Date using SQL

Problem Given a date, you want to subtract 30 days in the past using SQL. Said another way, get the date thirty

How to Subtract 30 Days from a Date using SQL

## How to Find the Week Number in PostgreSQL, MySQL, and SQL Server

Problem You need to figure out the week number from date, assuming Monday is the first day of the week using PostgreSQL,

How to Find the Week Number in PostgreSQL, MySQL, and SQL Server

## Replace using PostgreSQL

Problem You want to replace all occurrences of a substring with a new substring using PostgreSQL, MySQL, or SQL Server. Background The

Replace using PostgreSQL

In this article we are going to design and create a sample relational database you can use with MySql, PostgreSQL or Microsoft

## CREATE TABLE SQL

You can use the SQL CREATE TABLE command to create a new table in the database.  When you create a table you

CREATE TABLE SQL

## How to Get Today’s Date

Problem You want to use today’s date in your SQL query, but don’t want to type it in each day. Solution You

How to Get Today’s Date

## How to Get a Date 30 Days into the Future using SQL

How to Get a Date 30 Days into the Future. Problem You want to calculate a date 30 days into the Future

How to Get a Date 30 Days into the Future using SQL

## How to do an Impossible Join with String Split

In this article I’ll show you how to use STRING_SPLIT() to join two tables.  I call this the impossible join. I’ve come

How to do an Impossible Join with String Split

## Contains in SQL

Sooner or later, you want to know when a column contains in SQL another value.  In this article we’ll go over several

Contains in SQL

## What is a SQL Trigger?

What is a Database Trigger? A SQL trigger is special stored procedure that is run when specific actions occur within a database.

What is a SQL Trigger?