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
Over and partion by query results.

SQL SERVER – Adding Values WITH OVER and PARTITION BY

June 16, 2018
Pinal Dave
SQL Tips and Tricks
Ranking Functions, SQL Function, SQL Order By, SQL Scripts, SQL Server

How do you sum values for each group without GROUP BY and still keep every row? Here is how SUM with OVER and PARTITION BY answers a reader’s question.

Read More
A row of vessels with equal fill heights grouped across a selection boundary

How Does TOP WITH TIES Work in SQL Server? – Interview Question of the Week #159

February 4, 2018
Pinal Dave
SQL Interview Questions and Answers
SQL Function, SQL Order By, SQL Scripts, SQL Server

Question: How Does TOP WITH TIES Work in SQL Server?

Answer: This is an ancient question I just encountered in the recent Comprehensive Database Performance Health Check.

Read More
One red ceramic tile sits first while the remaining tiles follow in a tidy order

How to Keep Certain Records on Top While Ordering Data? – Interview Question of the Week #110

February 19, 2017
Pinal Dave
SQL Interview Questions and Answers
SQL Order By, SQL Scripts, SQL Server

An interview question: how do you keep one city on top while ordering data by name for the rest? The answer is a small trick in the ORDER BY clause.

Read More
The same ceramic buttons are arranged by color in one tray and by size in another

Sort Query Using Dynamic Variables Without EXEC – Interview Question of the Week #074

June 5, 2016
Pinal Dave
SQL Interview Questions and Answers
SQL Order By, SQL Scripts, SQL Server

How do you sort query results by a column passed in a variable? Here is how to sort query output dynamically without EXEC or sp_executesql.

Read More
A wooden xylophone with bars stepping from long to short, a red mallet resting between two neighbouring bars.

LAG and LEAD: Comparing Each Row With the One Before It

April 2, 2014
Pinal Dave
SQL Tips and Tricks
Ranking Functions, SQL Function, SQL Order By, SQL Server

Use LAG and LEAD for monthly comparisons, handle defaults and percent change, choose explicit frames, and detect status transitions.

Read More
SQL SERVER - MySQL - Order Column by Nearest Value for Any Integer

SQL SERVER – MySQL – Order Column by Nearest Value for Any Integer

November 27, 2013
Pinal Dave
SQL Tips and Tricks
MySQL, SQL Order By, SQL Scripts

How do you order column values by how close they are to any integer, such as -5? Here is a script that works the same way on SQL Server and MySQL.

Read More
Marbles tipped from a neat row into a bowl, landing mixed

Why a Clustered Index Does Not Guarantee Order Without ORDER BY

March 19, 2012
Pinal Dave
SQL Tips and Tricks
Clustered Index, Execution Plan, SQL Order By, SQL Server

Explain order without ORDER BY through parallel scans, NOLOCK allocation scans, alternate indexes, shared scans, and the explicit sort fix.

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

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