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
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
A rotary egg beater rests between separate mixing bowls and a jug of already beaten mixture

CTE Referenced Twice: Why the Query Runs It Twice

April 16, 2012
Pinal Dave
SQL Performance
CTE, Execution Plan, SQL Group By, Temp Table

Writing a CTE name two times can mean doing the work two times. Two small demos show when a temp table helps and when it only adds cost.

Read More
Repeated bundles of loose bed slats sit beside the compact assembled bed frame

Triangular Joins: The Hidden Row Explosion in Self-Joins

April 6, 2012
Pinal Dave
SQL Tips and Tricks
SQL Function, SQL Group By, SQL Joins, Temp Table

A small grouped result can hide a huge pile of row pairs. Here is how to count them and what to do instead.

Read More
Thirteen seedlings listed with the number of plants in their bed. The five North plants show 5, the three South plants and three East plants show 3, and the two plants with no bed show 2

Partitioned Aggregates: Compare Each Row to Its Own Group

August 11, 2011
Pinal Dave
SQL Tips and Tricks
SQL Function, SQL Group By, SQL Scripts, SQL Server

Partitioned aggregates let every row see a number for its own group, such as how many plants share its garden bed. This post uses thirteen seedlings in four beds to show PARTITION BY with COUNT and AVG. It also shows the integer division trap that turns every share into 0, and how to get one row per group.

Read More
Two results for the same eight trip costs. SUM(Cost) returns one row, 1385.00. SUM(Cost) OVER ( ) returns all eight rows with 1385.00 beside each one

Aggregates With the OVER Clause: A Total Beside Every Row

August 10, 2011
Pinal Dave
SQL Tips and Tricks
SQL Function, SQL Group By, SQL Scripts, SQL Server

Aggregates with the OVER clause put a total, an average or a minimum next to every row, so the rows do not collapse into one. This post uses eight trip costs to show the error a plain SUM gives, the fix, and the percent of the total for each row. It also shows how WHERE changes the total and how to filter on the result.

Read More
Loose wooden dowels and tied bundles rest on a slate tray beside four bundles inside an open wooden crate.

Aggregate Before the Join: Shrinking Rows Early With GROUP BY

May 4, 2010
Pinal Dave
SQL Performance
SQL Group By, SQL Joins, SQL Performance

Aggregate before the join only when the grouping preserves the required customer result. This private lab checks NULLs, missing matches, duplicate dimensions, complete outputs, actual plans, and reads.

Read More
A round pizza cut from two slightly different starting points, leaving one narrow sliver between the cuts.

ISO Week Numbers vs DATEPART(week): Grouping Sales by Week

August 25, 2009
Pinal Dave
SQL Tips and Tricks
SQL DateTime, SQL Function, SQL Group By, SQL Server

Group sales by ISO week and ISO year, compare DATEPART week behavior, and avoid New Year errors caused by session settings.

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

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