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 sloping egg rack at a market stall, one hand taking the oldest egg from the front, another adding a fresh one.

DELETE TOP With ORDER BY: Removing the Oldest Rows First

May 1, 2024
Pinal Dave
SQL Tips and Tricks
CTE, SQL Delete, SQL Order By, SQL Server, SQL Top

Use DELETE TOP safely through an ordered CTE, preview oldest rows, apply a supporting index, and remove eligible rows in bounded batches.

Read More
random rows

SQL SERVER – Techniques for Retrieving Random Rows

August 25, 2023
Pinal Dave
SQL Tips and Tricks
SQL Function, SQL Random, SQL Top

This post will explore various techniques to retrieve random rows in SQL Server and analyze their performance and randomness characteristics in depth.

Read More
A sieve holds a few kernels above a trough full of sifted grain, with a larger mound behind

TOP N Sort: Why a Small TOP Still Reads the Whole Table

November 3, 2021
Pinal Dave
SQL Performance
Execution Plan, SQL Index, SQL Order By, SQL Server, SQL Top

Explain TOP N Sort, compare an indexed ordered access path, and align filter and sort keys before adding indexes for frequent requests.

Read More
A hand pinning a red rosette on the largest marrow in a row already arranged by size on a village show table.

Filtering on a Window Function Without QUALIFY in SQL Server

October 5, 2021
Pinal Dave
SQL Tips and Tricks
CTE, Ranking Functions, SQL Server, SQL Top

Filter window results without QUALIFY using CTEs and derived tables, compare TOP WITH TIES, and preserve partition and tie rules.

Read More
Gouache painting of a long orchard row with one basket at the first tree holding a single vermilion apple

Top 1 and Index Scan: A Scan That Stops After One Row

April 1, 2021
Pinal Dave
SQL Performance
Execution Plan, SQL Index, SQL Scripts, SQL Top

Top 1 and index scan can sit in the same plan, and the scan still reads only a few pages. This post runs six queries on a table of 100,000 rows and reads their logical reads. It shows why TOP 1 reads three pages in one case and every page in another.

Read More
A knife block with five large knives, beside one small pot holding all the smaller utensils bunched together.

Top N Plus Others: Grouping the Rest Into One Row

December 3, 2020
Pinal Dave
SQL Tips and Tricks
Ranking Functions, SQL Group By, SQL Scripts, SQL Server, SQL Top

Create top N plus others summaries with deterministic category ranking, one remainder total, stable labels, and explicit display ordering.

Read More
A hand picking the three ripest red strawberries from each plant along a garden row

Top N per Group: Three Ways and Which Is Fastest

January 29, 2015
Pinal Dave
SQL Performance
Execution Plan, Ranking Functions, SQL Performance, SQL Server, SQL Top

Compare top N per group with ROW_NUMBER, APPLY and a correlated subquery, define tie behavior, and measure plans with a supporting index.

Read More
1 2 Next
  • Books
  • Testimonials
  • Privacy Policy

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