This month's discount Comprehensive Database Performance Health Check · Testimonials
SQLAuthority with Pinal Dave
Home
  • Consulting
    • Health Check
  • Free Videos
  • All Articles
    • AI
    • SQL Performance
    • SQL Tips and Tricks
    • Interview Questions and Answers
    • SQL Puzzle
    • SQL Video
    • SQLAuthority News
    • Personal
  • Books
  • Consulting
A red hat reflected three times in a tailor's three-panel mirror, a hand reaching for the real one

Join Duplicates: Stop Hiding Extra Rows With SELECT DISTINCT

June 13, 2017
Pinal Dave
SQL Tips and Tricks
Duplicate Records, SQL Distinct, SQL Group By, SQL Joins, SQL Server

Diagnose join duplicates before using DISTINCT, verify order and payment totals, and choose aggregation or EXISTS for the required result.

Read More
A row of small bud vases with flowers in seasonal order, a hand moving a red poppy into its place.

MONTH, DATEPART and DATENAME: Getting Month Names and Numbers Right

May 20, 2015
Pinal Dave
SQL Tips and Tricks
SQL DateTime, SQL Function, SQL Group By, SQL Server

Use DATENAME for month labels, compare MONTH and DATEPART, control language and culture, and group sales without combining different years.

Read More
A basketball net above a basketball with a different practice ball kept outside

Makers That Sell PCs but Not Laptops: HAVING With Conditional Counts

February 25, 2014
Pinal Dave
SQL Tips and Tricks
SQL CASE, SQL Group By, SQL Sub Query

One WHERE clause cannot say ‘has a PC but no laptop’. Here are three queries that can, and the NULL trap.

Read More
Birds on three telegraph wires at dusk, each wire mostly one kind of bird with a few others mixed in.

Finding the Most Frequent Value per Group in T-SQL

October 28, 2013
Pinal Dave
SQL Tips and Tricks
Ranking Functions, SQL Group By, SQL Scripts, SQL Server

Find the most frequent value in each group, choose a tie policy, and compare categorical modes with averages and numeric percentiles.

Read More
A bulb planter beside separate clusters of shoots and empty planting hollows

Cohort Retention Tables in T-SQL: From Raw Events to a Grid

October 6, 2013
Pinal Dave
SQL Tips and Tricks
Business Intelligence, CTE, SQL DateTime, SQL Group By

Build a retention grid from raw orders with five rows you can check by eye. Includes the DISTINCT rule and why unfinished months show NULL.

Read More
Small streams joining larger rivers that merge into one wide river, a red bridge across it.

Subtotals and Grand Totals With ROLLUP and GROUPING SETS

March 2, 2013
Pinal Dave
SQL Tips and Tricks
SQL Group By, SQL Reports, SQL Server, SQL Union clause

Build region, product, and grand totals with ROLLUP, CUBE, and GROUPING SETS, then label subtotal rows and compare plans.

Read More
Three boxes for the same eight pledges: a plain SUM returns 1 row holding 4,800.00, GROUP BY MemberID returns 6 rows, one per member, and SUM with OVER returns all 8 rows, each with the total

Aggregate and Detail Columns in One Query: GROUP BY or OVER

February 26, 2013
Pinal Dave
SQL Tips and Tricks
SQL Function, SQL Group By, SQL Scripts, SQL Server

Aggregate and detail columns in one query fail with Msg 8120 until you pick a way to keep the rows. This post compares GROUP BY, a scalar subquery and OVER on one small table, adds PARTITION BY and a share of the total, and then combines GROUP BY with OVER. Every result comes from SQL Server 2025.

Read More
Previous 1 2 3 4 Next
  • Books
  • Testimonials
  • Privacy Policy

© 2006 – 2026 All rights reserved. pinal @ SQLAuthority.com