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
Query Execution Plan.

SQL SERVER – Simple Puzzle with UNION – Part 2

September 6, 2013
Pinal Dave
SQL Puzzle
SQL Union clause

Another back to basics puzzle with UNION: run three queries using UNION ALL, ORDER BY and DISTINCT, then compare their execution plans.

Read More
SQL SERVER - Simple Puzzle with UNION

SQL SERVER – Simple Puzzle with UNION

September 5, 2013
Pinal Dave
SQL Puzzle
SQL Scripts, SQL Union clause

Try this simple puzzle with UNION and ORDER BY. Guess what each of the three queries returns, and see why one of them fails with Msg 108 and Msg 104.

Read More
Two hands taking blocks from two sorted bins, one of cubes and one of cylinders, beside a messy heap of blocks.

Rewriting OR Conditions So the Index Gets Used

July 29, 2013
Pinal Dave
SQL Performance
Execution Plan, SQL Index, SQL Performance, SQL Server, SQL Union clause

Rewrite OR conditions with separate seeks, preserve duplicate and NULL behavior, and compare plans before choosing UNION or recompilation.

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
Execution plan with SQL query and cost estimates.

SQL SERVER – Return Specific Row to at the Bottom of the Resultset – T-SQL Script – Part 2

April 25, 2013
Pinal Dave
SQL Tips and Tricks
SQL Scripts, SQL Union clause

Part 2 on how to return a specific row at the bottom of the resultset. Earlier I used CASE in ORDER BY, and this time I show the UNION ALL method.

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
SQL SERVER - UNION Not Allowed but OR Allowed in Index View - Limitation of the View 6

SQL SERVER – UNION Not Allowed but OR Allowed in Index View – Limitation of the View 6

September 22, 2010
Pinal Dave
SQL Tips and Tricks
SQL Index, SQL Scripts, SQL Union clause, SQL View

UNION not allowed in an indexed view can surprise you. Limitation of the view 6 shows the script that fails and how the OR operator is allowed instead.

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

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