{
    "url": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all",
    "locale": "en",
    "title": "UNION vs UNION ALL: Knowledge hub | DeLaParra Services",
    "description": "Both stack result sets. UNION removes duplicates (and pays for a sort/hash); UNION ALL keeps everything and is faster.",
    "alternates": {
        "en": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all",
        "nl": "https://delaparra-services.nl/nl/kennisbank/union-vs-union-all"
    },
    "formats": {
        "csv": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all.csv",
        "md": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all.md",
        "json": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all.json",
        "zip": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all.zip",
        "pdf": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all.pdf"
    },
    "downloads": [
        {
            "url": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all.csv",
            "encodingFormat": "text/csv",
            "name": "union-vs-union-all.csv"
        },
        {
            "url": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all.json",
            "encodingFormat": "application/json",
            "name": "union-vs-union-all.json"
        },
        {
            "url": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all.md",
            "encodingFormat": "text/markdown",
            "name": "union-vs-union-all.md"
        },
        {
            "url": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all.pdf",
            "encodingFormat": "application/pdf",
            "name": "union-vs-union-all.pdf"
        },
        {
            "url": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all.zip",
            "encodingFormat": "application/zip",
            "name": "union-vs-union-all.zip"
        },
        {
            "url": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all/skills.zip",
            "encodingFormat": "application/zip",
            "name": "union-vs-union-all-skills.zip"
        }
    ],
    "markdown": "1. [Home](<https://delaparra-services.nl/>) \n1. [Knowledge hub](<https://delaparra-services.nl/knowledge-hub>) \n1. [UNION vs UNION ALL](<https://delaparra-services.nl/knowledge-hub/union-vs-union-all>)\n\n  \n\nCategory: SQL \n\n# UNION vs UNION ALL\n\n  Explained by [Reinier de la Parra](<https://delaparra-services.nl/about>)  Updated November 25, 2026    \n\n## What is UNION vs UNION ALL?\n\n \n\nUNION vs UNION ALL: Both stack result sets. UNION removes duplicates (and pays for a sort/hash); UNION ALL keeps everything and is faster. ` UNION ` and ` UNION ALL ` stack the results of two queries into one list. Both queries must return the same number of columns with compatible types. The difference is duplicates. ` UNION ` removes duplicate rows, which requires sorting or hashing the whole result. ` UNION ALL ` keeps everything as it is, which makes it faster.\n\n \n\nDefinition source [Coders Lingo](<https://coderslingo.com/resources/open-dataset/>), [CC BY 4.0](<https://creativecommons.org/licenses/by/4.0/>)\n\n \n\n## Frequently asked questions about UNION vs UNION ALL\n\n  \n\n### What should you keep in mind with UNION vs UNION ALL?\n\n \n\nUse ` UNION ALL ` by default, and only switch to ` UNION ` when you really need duplicates removed. If the two queries cannot overlap, for example active and archived orders from separate tables, ` UNION ` just does extra work for nothing. Add ` ORDER BY ` once at the end of the combined query; ordering inside each part is ignored or not allowed in most databases.\n\n    \n\n### What does an example of UNION vs UNION ALL look like?\n\n \n\n```\nSELECT id FROM active UNION ALL SELECT id FROM archived;\n```\n\n \n\n## At a glance\n\n   CategorySQL Explained by[Reinier de la Parra](<https://delaparra-services.nl/about>) UpdatedNovember 25, 2026\n\n \n\n## More SQL terms\n\n \n\n- [RIGHT (OUTER) JOIN](<https://delaparra-services.nl/knowledge-hub/right-outer-join>) \n- [ROW\\_NUMBER](<https://delaparra-services.nl/knowledge-hub/row-number>) \n- [running total](<https://delaparra-services.nl/knowledge-hub/running-total>) \n- [SELF JOIN](<https://delaparra-services.nl/knowledge-hub/self-join>) \n- [SERIALIZABLE](<https://delaparra-services.nl/knowledge-hub/serializable>) \n- [subquery](<https://delaparra-services.nl/knowledge-hub/subquery>)\n\n \n\n[All terms starting with U](<https://delaparra-services.nl/knowledge-hub#letter-u>)\n\n \n\n## Skills\n\n \n\n- ### SQL Performance Optimization Assistant\n\n \n\n'Universal SQL performance optimization assistant for comprehensive query tuning, indexing strategies, and database performance analysis across all SQL databases (MySQL, PostgreSQL, SQL Server, Oracle). Provides execution plan analysis, pagination optimization, batch operations, and performance monitoring guidance.'\n\n [View skill](<https://delaparra-services.nl/skills/sql-optimization>) [Download zip](<https://delaparra-services.nl/skills/sql-optimization/download>) \n- ### SQL Code Review\n\n \n\n'Universal SQL code review assistant that performs comprehensive security, maintainability, and code quality analysis across all SQL databases (MySQL, PostgreSQL, SQL Server, Oracle). Focuses on SQL injection prevention, access control, code standards, and anti-pattern detection. Complements SQL optimization prompt for complete development coverage.'\n\n [View skill](<https://delaparra-services.nl/skills/sql-code-review>) [Download zip](<https://delaparra-services.nl/skills/sql-code-review/download>) \n- ### Laravel Database Optimization\n\n \n\nLaravel database optimization patterns. Use when writing Eloquent queries, creating migrations, configuring caching, debugging slow queries, or optimizing database performance. Triggers on tasks involving N+1 queries, indexing, Redis caching, pagination, or database transactions.\n\n [View skill](<https://delaparra-services.nl/skills/laravel-database-optimization>) [Download zip](<https://delaparra-services.nl/skills/laravel-database-optimization/download>)\n\n [Download all skills (zip)](<https://delaparra-services.nl/knowledge-hub/union-vs-union-all/skills.zip>)\n\n \n\n## Manuals\n\n \n\n- [Writing SQL queries and migrations](<https://delaparra-services.nl/manuals/sql-queries-en-migraties>) \n- [PHP and Composer](<https://delaparra-services.nl/manuals/php-en-composer>)\n\n \n\n## Related services\n\n \n\n- [Custom software and web applications](<https://delaparra-services.nl/services#service-03>)\n\nPerhaps your customers need somewhere to download their invoices, or your staff are managing bookings in a spreadsheet. \n- [AI code review](<https://delaparra-services.nl/services#service-05>)\n\nWhen you push your new change, I will review your code, help your agent avoid the same mistake again, and get your app ready for deployment.\n\n \n\n## Need any help?\n\n \n\nStuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.\n\n  [Get in touch](<https://delaparra-services.nl/availability>)\n\n[HTML version](https://delaparra-services.nl/knowledge-hub/union-vs-union-all)\n",
    "structured_data": {
        "@context": "https://schema.org",
        "@graph": [
            {
                "@type": "Organization",
                "@id": "https://delaparra-services.nl/#practice",
                "logo": "https://delaparra-services.nl/logo.png",
                "name": "DeLaParra Services",
                "legalName": "DeLaParra Services",
                "url": "https://delaparra-services.nl/",
                "description": "Bespoke software, web applications and mobile apps, developed in Laravel by a single developer in Groningen. Fixed price agreed in advance, full source code provided upon delivery.",
                "email": "info@delaparra-services.nl",
                "address": {
                    "@type": "PostalAddress",
                    "addressLocality": "Groningen",
                    "addressRegion": "Groningen",
                    "addressCountry": "NL"
                },
                "areaServed": "Groningen, the Netherlands",
                "knowsLanguage": [
                    "en",
                    "nl"
                ],
                "knowsAbout": [
                    "Web design and development",
                    "App development",
                    "Custom software and web applications",
                    "OpenSpec",
                    "AI code review",
                    "Your own coding agent"
                ],
                "founder": {
                    "@id": "https://delaparra-services.nl/#person"
                }
            },
            {
                "@type": "FAQPage",
                "@id": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all#webpage",
                "url": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all",
                "name": "UNION vs UNION ALL: Knowledge hub | DeLaParra Services",
                "description": "Both stack result sets. UNION removes duplicates (and pays for a sort/hash); UNION ALL keeps everything and is faster.",
                "isPartOf": {
                    "@id": "https://delaparra-services.nl/#website"
                },
                "about": {
                    "@type": "DefinedTerm",
                    "@id": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all#term",
                    "name": "UNION vs UNION ALL",
                    "description": "Both stack result sets. UNION removes duplicates (and pays for a sort/hash); UNION ALL keeps everything and is faster.",
                    "termCode": "union-vs-union-all",
                    "url": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all",
                    "inLanguage": "en",
                    "keywords": "SQL",
                    "dateModified": "2026-11-25T17:46:31+00:00",
                    "inDefinedTermSet": {
                        "@id": "https://delaparra-services.nl/knowledge-hub#terms"
                    },
                    "isPartOf": {
                        "@id": "https://delaparra-services.nl/knowledge-hub#dataset"
                    },
                    "subjectOf": [
                        {
                            "@id": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all#webpage"
                        },
                        {
                            "@id": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all#dataset"
                        }
                    ]
                },
                "inLanguage": "en",
                "breadcrumb": {
                    "@id": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all#breadcrumb"
                },
                "mainEntity": [
                    {
                        "@type": "Question",
                        "name": "What is UNION vs UNION ALL?",
                        "acceptedAnswer": {
                            "@type": "Answer",
                            "text": "Both stack result sets. UNION removes duplicates (and pays for a sort/hash); UNION ALL keeps everything and is faster. UNION and UNION ALL stack the results of two queries into one list. Both queries must return the same number of columns with compatible types. The difference is duplicates. UNION removes duplicate rows, which requires sorting or hashing the whole result. UNION ALL keeps everything as it is, which makes it faster."
                        }
                    },
                    {
                        "@type": "Question",
                        "name": "What should you keep in mind with UNION vs UNION ALL?",
                        "acceptedAnswer": {
                            "@type": "Answer",
                            "text": "Use UNION ALL by default, and only switch to UNION when you really need duplicates removed. If the two queries cannot overlap, for example active and archived orders from separate tables, UNION just does extra work for nothing. Add ORDER BY once at the end of the combined query; ordering inside each part is ignored or not allowed in most databases."
                        }
                    },
                    {
                        "@type": "Question",
                        "name": "What does an example of UNION vs UNION ALL look like?",
                        "acceptedAnswer": {
                            "@type": "Answer",
                            "text": "SELECT id FROM active UNION ALL SELECT id FROM archived;"
                        }
                    }
                ],
                "author": {
                    "@id": "https://delaparra-services.nl/#person"
                },
                "mentions": [
                    {
                        "@id": "https://delaparra-services.nl/skills/sql-optimization#skill"
                    },
                    {
                        "@id": "https://delaparra-services.nl/skills/sql-code-review#skill"
                    },
                    {
                        "@id": "https://delaparra-services.nl/skills/laravel-database-optimization#skill"
                    },
                    {
                        "@id": "https://delaparra-services.nl/manuals/sql-queries-en-migraties#article"
                    },
                    {
                        "@id": "https://delaparra-services.nl/manuals/php-en-composer#article"
                    }
                ]
            },
            {
                "@type": "BreadcrumbList",
                "@id": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all#breadcrumb",
                "itemListElement": [
                    {
                        "@type": "ListItem",
                        "position": 1,
                        "name": "Home",
                        "item": "https://delaparra-services.nl/"
                    },
                    {
                        "@type": "ListItem",
                        "position": 2,
                        "name": "Knowledge hub",
                        "item": "https://delaparra-services.nl/knowledge-hub"
                    },
                    {
                        "@type": "ListItem",
                        "position": 3,
                        "name": "UNION vs UNION ALL"
                    }
                ]
            },
            {
                "@type": "Person",
                "@id": "https://delaparra-services.nl/#person",
                "name": "Reinier de la Parra",
                "url": "https://delaparra-services.nl/about"
            },
            {
                "@type": "Dataset",
                "@id": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all#dataset",
                "name": "UNION vs UNION ALL",
                "description": "Both stack result sets. UNION removes duplicates (and pays for a sort/hash); UNION ALL keeps everything and is faster.",
                "url": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all",
                "identifier": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all#dataset",
                "about": {
                    "@id": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all#term"
                },
                "creator": {
                    "@id": "https://delaparra-services.nl/#practice"
                },
                "publisher": {
                    "@id": "https://delaparra-services.nl/#practice"
                },
                "license": "https://creativecommons.org/licenses/by/4.0/",
                "creditText": "Coders Lingo (https://coderslingo.com/resources/open-dataset/), CC BY 4.0",
                "isAccessibleForFree": true,
                "inLanguage": "en",
                "keywords": "SQL",
                "version": "2026-11-25",
                "dateModified": "2026-11-25T17:46:31+00:00",
                "isPartOf": {
                    "@type": "Dataset",
                    "@id": "https://delaparra-services.nl/knowledge-hub#dataset",
                    "name": "IT terms from A to Z",
                    "url": "https://delaparra-services.nl/knowledge-hub"
                },
                "includedInDataCatalog": {
                    "@type": "DataCatalog",
                    "@id": "https://delaparra-services.nl/knowledge-hub#catalog",
                    "name": "Knowledge hub data catalog",
                    "url": "https://delaparra-services.nl/knowledge-hub"
                },
                "distribution": [
                    {
                        "@type": "DataDownload",
                        "name": "union-vs-union-all.csv",
                        "encodingFormat": "text/csv",
                        "contentUrl": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all.csv",
                        "inLanguage": "en",
                        "dateModified": "2026-11-25T17:46:31+00:00",
                        "license": "https://creativecommons.org/licenses/by/4.0/"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "union-vs-union-all.json",
                        "encodingFormat": "application/json",
                        "contentUrl": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all.json",
                        "inLanguage": "en",
                        "dateModified": "2026-11-25T17:46:31+00:00",
                        "license": "https://creativecommons.org/licenses/by/4.0/"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "union-vs-union-all.md",
                        "encodingFormat": "text/markdown",
                        "contentUrl": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all.md",
                        "inLanguage": "en",
                        "dateModified": "2026-11-25T17:46:31+00:00",
                        "license": "https://creativecommons.org/licenses/by/4.0/"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "union-vs-union-all.pdf",
                        "encodingFormat": "application/pdf",
                        "contentUrl": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all.pdf",
                        "inLanguage": "en",
                        "dateModified": "2026-11-25T17:46:31+00:00",
                        "license": "https://creativecommons.org/licenses/by/4.0/"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "union-vs-union-all.zip",
                        "encodingFormat": "application/zip",
                        "contentUrl": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all.zip",
                        "inLanguage": "en",
                        "dateModified": "2026-11-25T17:46:31+00:00",
                        "license": "https://creativecommons.org/licenses/by/4.0/"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "union-vs-union-all-skills.zip",
                        "encodingFormat": "application/zip",
                        "contentUrl": "https://delaparra-services.nl/knowledge-hub/union-vs-union-all/skills.zip",
                        "inLanguage": "en",
                        "dateModified": "2026-11-25T17:46:31+00:00",
                        "license": "https://creativecommons.org/licenses/by/4.0/"
                    }
                ]
            }
        ]
    }
}