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
sql puzzle

SQL Puzzle – Retrieve the Unique Evens Under 10

November 21, 2023
Pinal Dave
SQL Puzzle
SQL Distinct

In that spirit, let me walk through a bite-sized SQL puzzle that helps reinforce some key concepts. Let us see Retrieve the Unique Evens Under 10 puzzle.

Read More
Gouache painting of a heap of pebbles with one of each kind lined along driftwood, one pebble vermilion

Count Distinct in Access: Use a Subquery in FROM

June 17, 2021
Pinal Dave
SQL Tips and Tricks
SQL Distinct, SQL Scripts, SQL Server

Count distinct in Access with a subquery in the FROM clause, because Access SQL does not accept COUNT(DISTINCT). Includes NULL and multi-column cases.

Read More
Gouache painting of baskets of apples and pears with a line of leftover apples, one of them vermilion

EXCEPT Operator in SQL Server: Distinct Rows and Differences

December 26, 2018
Pinal Dave
SQL Tips and Tricks
SQL Distinct, SQL Operator, SQL Scripts, SQL Server

The EXCEPT operator returns the rows of one query that are missing from another, with duplicates removed. This post shows the difference between two small order tables, the old WHERE 1 = 0 trick for distinct rows, and how NULLs behave.

Read More
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
Two strips of matching leaf wallpaper side by side on a floor, one with a single red leaf that differs.

Finding Rows That Differ Between Two Tables With EXCEPT

June 23, 2014
Pinal Dave
SQL Tips and Tricks
SQL Distinct, SQL NULL, SQL Operator, SQL Server

Use EXCEPT to find differing rows in both directions, compare selected columns, handle NULLs, and distinguish changed keys from additions.

Read More
Gouache painting of two crates of pears, one holding duplicates with a red pear and one holding only single pears

UNION vs UNION ALL in SQL Server: What Each One Does

April 26, 2013
Pinal Dave
SQL Tips and Tricks
SQL Distinct, SQL Scripts, SQL Server, SQL Union clause

UNION vs UNION ALL comes down to duplicates: UNION removes them and UNION ALL keeps every row. This post tests both on two small store tables. It also covers sorting, a total row at the bottom, mixed operators and data type rules.

Read More
Two trays pair a blue bowl with a cream jug and a blue jug with a cream bowl.

Count Distinct Pairs: Keep the Columns Together

June 27, 2010
Pinal Dave
SQL Tips and Tricks
Developer, SQL Distinct, SQL NULL, SQL Server, SQL Sub Query

Count distinct pairs by keeping their columns together. A small T-SQL example shows why concatenated labels can collide. Choose whether incomplete pairs belong in the count.

Read More
  • Books
  • Testimonials
  • Privacy Policy

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