Category: Blog

  • UNION vs UNIONALL: #SQLNewBlogger

    While writing another post I realized my UNION query didn’t work as one might initiall expect, so I decided a short post was worth writing. This is based on a previous post on QUOTENME().

    Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers.

    Missing a Row

    When I ran this code, I got only a single row. There’s a UNION here, so why? One would expect two rows from these queries.

    2026-05_0287

    Let’s change to UNION ALL. Now we see this:

    2026-05_0288

    You can likely spot the reason, but it’s because both rows in the result are the same. In this cse, UNION is designed to remove duplicates. In the docs, it explicitly says

    • UNION ALL – Includes duplicates
    • UNION Excludes duplicates

    We can see this in this examples I’ve got this code that gives me two virtual tables of numbers, some of which are duplicate:

    WITH myTally(n)
    AS
    (SELECT n 
     FROM (VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10)) a(n)
    )
    , myTally2(n)
    AS
    (SELECT n 
     FROM (VALUES (1), (20), (3), (40), (5), (60), (7), (08), (9), (100)) b(n)
    )
    SELECT n
    FROM myTally
    UNION 
    SELECT n
     FROM myTally2

    When I run the query, with UNION, I see these results, 14 rows:

    2026-05_0289

    If I change to UNION ALL, 20 results.

    2026-05_0290

    Use UNION when you want unique things. UNION ALL if you need to see ALL The Rows.

    SQL New Blogger

    This post was about 8 minutes spent after I finished the other post. It is a quick expansion on something I saw in another post, it has a separate focus, and it shows I’ve realized something and built on previous work.

    You can showcase these skills.

  • Join Me in San Diego to Learn about AI and Software Development

    You might have seen this graphic on the side of my blog. It’s my discount code for VS Live in San Diego this September.

    I got accepted to talk about LLMs on your local machine or data center, which is something I think will be more and more important in the future. Already the EU is less thrilled with US tech giants, and I suspect many other companies will rethink allowing their data to flow to non self-hosted LLMs.

    I’m also talking about the Data API Builder, which makes software development much easier for software engineers, and includes an MCP server. I’m excited to showcase how this has grown over the last few years and think it’s a cool technology.

    Register today, use my code, save your company some money, and join me in Sunny San Diego. The Padres aren’t in town, but we can still enjoy some time in San Diego.

  • Vacation Week

    It might seem I’ve been gone a lot, and I have been. April had me taking three trips, and May wasn’t better with 3 before this, but those were for work. This week the family and I are on a cruise to Alaska, spending a week traveling with the kids.

    I know it will be amazing, but no blogs this week while I take some time to recharge.

  • The Book of Redgate: Profits

    Redgate is a for-profit company. We look to make money by building and selling tools that help you. If we do a good job, we make money. If we don’t, you shouldn’t buy our tools.

    I found this value to be very interesting:

    2026-04_0228

    The next page has this statement:

    Focusing purely on the numbers is a sure way to kill Red Gate’s culture. We believe that if we focus on the game – building awesome products that people want to buy, and then persuading them to buy them – then success will follow.

    Profits matter. Certainly all of us want to be paid (and get a bonus of some sort). With the changes in Redgate’s board this year, this is a piece of culture that I believe in and advocate to keep as an item of focus.

    We watch profits, but we don’t optimize for profit, we aim to optimize in building better and better products that meet the need of our customers and prove their value from an ROI standpoint. Especially in this era of subscription software.

    Our goal is what’s in the quote: build awesome products.

    I have a copy of the Book of Redgate from 2010. This was a book we produced internally about the company after 10 years in existence. At that time, I’d been there for about 3 years, and it was interesting to learn a some things about the company. This series of posts looks back at the Book of Redgate 15 years later.