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
Gouache painting of two trays of buttons, one mixed together and one sorted by size, with one large red button

Effect of Collation on Result Sets in SQL Server

September 19, 2012
Pinal Dave
SQL Tips and Tricks
SQL Collation, SQL Group By, SQL Order By, SQL Scripts

The effect of collation on result sets is easy to see once you run the same query against two collations. This post builds a small demo and shows how sorting, comparing and grouping change. It also explains collation conflicts, including the one temp tables cause.

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

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