Useful sql database resources
to consider
(Updated
2024-Feb-27th)
Quotes:
- "...write a subquery to get that one value, but the LATERAL will ... get multiple values from the derived dataset." -- Rob Reid, Aug 2021.
- "[When] you need to join to a subquery and can't do it with a JOIN, try using CROSS APPLY or OUTER APPLY." -- Ben Brumm, April 2021.
- "LATERAL JOIN's allow you to reuse [non-aggregate] calculations, making your queries neat and legible." -- PopSQL, Oct 2020.
- "...need to iterate over each item ... and apply a function ... using LATERAL JOIN's [, not stored procedures]..." -- Steve Pousty, Aug 2020.
- "If you add a LATERAL to your subqueries then each subquery can share column references." -- Steve Pousty, Aug 2020.
- "LATERAL JOIN's ... enable ... new queries that were previously only tractable with procedural code." -- Dan Robinson, Dec 2014.
- "...CROSS APPLY is ... like doing a CROSS JOIN with a correlated subquery instead of a derived table." -- Jeff Smith, Oct 2007.
- "Always count the number of rows before and after a JOIN." -- Alex Petralia, July 2017.
- "SQL JOIN's are not ... intuitive. They require critical thought and foresight." -- Alex Petralia, July 2017.
- "A prudent analyst must always be aware of ... JOIN duplications and misses." -- Alex Petralia, July 2017.
- "A JOIN is not strictly a set operation that can be described with Venn Diagrams." -- Lukas Eder, July 2016.
- "A JOIN is always a Cartesian product with a predicate, and possibly a UNION ..." -- Lukas Eder, July 2016.
- "FULL OUTER JOIN's are especially useful for tracking down data integrity problems." -- William McEvoy, July 2008.
- "Every JOIN always involves a Cartesian product followed by choosing the desired data from the result." -- Baron Schwartz, Oct 2005.
- "The ... FULL OUTER JOIN ... is used to merge the contents of both tables." -- Maryela Weihrauch, April 2000.
- "FULL OUTER JOIN ... is used basically to merge data from different sources ..." -- Cesar A. Galindo-Legaria, May 1994.
- "LEFT JOIN's are used ... frequently ... because they model hierarchical data ... in the ... most natural way." -- Michael M. David, March 1992.
- "SQL Server's pivoting capabilities (AKA crosstab queries) have many practical applications." -- Itzik Ben-Gan, Dec 2006.
- "You can use pivoting in different ways, ... in reporting, custom aggregates, and relational division." -- Itzik Ben-Gan, Dec 2006.
Free Interactive Training:
Books:
- I. Ben-Gan, T-SQL Fundamentals, 3rd Ed., Microsoft Press, 2016 / 2008.
- I. Ben-Gan, T-SQL Window Functions, 2nd Ed., Microsoft Press, 2019.
- T. Connolly, C. Begg, Database Systems, 6th
Ed., Pearson, 2014.
- L. Bohm, Refactoring Legacy T-SQL for Improved Performance, Apress, 2020.
- B. Forta, Sams Teach Yourself SQL in 10
Minutes, 5th Ed., Pearson, 2019 / 1999.
- B. Forta, Sams Teach Yourself Microsoft SQL Server T-SQL in
10 Minutes, 2nd Ed., Pearson, 2017.
- B. Karwin, SQL Antipatterns, Pragmatic
Programmers, 2010.
- K. Kellenberger, L. Everest, Beginning T-SQL, 4th Ed., Apress, 2021.
- K. Kellenberger, C. Groom, E. Pollack, Expert T-SQL Window Functions in SQL Sever 2019, 2nd Ed., Apress, 2019.
- K. Kellenberger, Beginning SQL Server Reporting Services, Apress, 2016.
- A. Molinaro, SQL Cookbook, O'Reilly, 2005.
- A. Silberschatz, H.F. Korth, S. Sudarshan, Database System
Concepts, 6th Ed., McGraw-Hill, 2010.
- P. Turley, Professional Microsoft SQL Server 2016 Reporting Services and Mobile Reports, Wrox, 2017.
- M. Russo, A. Ferrari, Tabular Modeling in MS SQL Server Analysis Services, 2nd Ed., Microsoft Press, 2017 / 2012.
Courses:
- G. Boetticher, Database Management Systems, UHCL CSCI 5333 course,
2016. (YOUTUBE PLAYLIST)
- J.D.N. Dionisio, Introduction to Database Systems, LMU CMSI 486 course,
2012.
- B. Finnegan, Introduction to Databases, Peirce College BIS 235
course, 2013.
- Y.-S. Lin, Database Management Systems, PSU CMPSC 431W course,
2015. (YOUTUBE PLAYLIST)
- J. Widom, Databases, Stanford MOOC course, 2013. (YOUTUBE PLAYLIST)
- C. Faloutsos, A. Pavlo, Database Applications, CMU 15-415/615 course, 2016.
- A. Pavlo, Database Systems, CMU 15-445/645 course, 2017. (YOUTUBE PLAYLIST)
- A. Pavlo, Advanced Database Systems, CMU 15-721 course, 2018. (YOUTUBE PLAYLIST)
Videos:
- Tim Hall, "[Oracle] SQL for Beginners":
- Graeme Malcolm & Geoff Allix, "[SQL Server] Querying with Transact-SQL":
- Simon Elliston Ball, "When to NoSQL and When to Know SQL", YouTube video, 2015.
- Itzik Ben-Gan, "[T-SQL] Query Tuning Tips Concerning Table Expressions", PASS Data Community Summit talk, 2021.
- Itzik Ben-Gan, "Workarounds for T-SQL Restrictions and Limitations", PASS Virtual Summit talk, Nov 2020.
- Itzik Ben-Gan, "Missing T-SQL Querying Features for Handling NULL's and for Data Analysis", PASS Summit talk, Nov 2019.
- Kevin Boles, "Common T-SQL Mistakes (Session 1)", Swedish SQL Server User Group session, Oct 2014.
- Ben Brumm, "Complex SQL Breakdown", YouTube video, May 2023.
- Ben Brumm, "The Best Way to Store Phone Numbers in an SQL Database", YouTube video, Dec 2022.
- Ben Brumm, "[PostgreSQL] How to Use pgAdmin", YouTube video, Oct 2022.
- Ben Brumm, "SQL Window Functions Explained", YouTube video, Aug 2022.
- Ben Brumm, "A Better Way to Store Address Data in a Database", YouTube video, July 2022.
- Ben Brumm, "How to Create a Database Design from an Idea", YouTube video, May 2022.
- Ben Brumm, "SQL Indexes - Examples and Tips", YouTube video, March 2022.
- Ben Brumm, "Seven Database Design Mistakes to Avoid", YouTube video, Jan 2022.
- Ben Brumm, "Database Design for Custom Fields", YouTube video, Sep 2020.
- Will Cross, "SQL Indexing Best Practices", YouTube video, Sep 2022.
- Kevin Devine, "How to Think in SQL: A Set-Based Mindset", Stir Trek talk, 2015.
- David DeWitt, "SQL Query Optimization: Why is it so hard to get right?", YouTube video, 2018.
- Lukas Eder, "How Modern SQL Databases Come Up with Algorithms that You Would Have Never Dreamed Of", Voxxed Days Zürich talk, 2017.
- Lukas Eder, "Ten SQL Tricks that You Didn't Think Were Possible", Devoxx France talk, 2016.
- Stéphane Faroult, "Rewriting SQL Queries for Performance in 9 Minutes", YouTube video, Feb 2009.
- Mike Girvin, "Power Query to Import from SQL Server Database in Excel or Power BI Desktop", YouTube video, Sep 2018.
- Richard Hipp, "SQLite: Misunderstood and Underutilized", Skookum Digital Works Tech Talk, 2015.
- Richard Hipp, "SQLite as an Application File Format", SouthEast LinuxFest talk, 2014.
- Richard Hipp, "An Introduction to SQLite", Google talk, 2006.
- Connor McDonald, "Leaner, Faster Code with Advanced SQL Techniques", Oracle OpenWorld talk, 2017.
- Brent Ozar, "How to Think Like the SQL Server Engine", YouTube video, 2020.
- Srivathsava Rangarajan, "EXPLAIN PLAN's and You", Postgres Open talk, 2019.
- Alex Robinson, "The How's and Why's of a Distributed SQL Database", Strange Loop talk, 2017.
- Chris Saxon, "[Oracle] Optimizing Functions in the WHERE Clause", YouTube video, April 2022.
- Chris Saxon, "[Oracle] Splitting Rows into Buckets with SQL", YouTube video, Sep 2021.
- Chris Saxon, "[Oracle] (Perf 9/9) How to Find Slow SQL", YouTube video, July 2020.
- Chris Saxon, "[Oracle] (Perf 8/9) How do Make Inserts, Updates and Deletes Faster", YouTube video, June 2020.
- Chris Saxon, "[Oracle] (Perf 7/9) How do Nested Loop, Hash and Merge Joins Work?", YouTube video, June 2020.
- Chris Saxon, "[Oracle] (Perf 6/9) Count Millions of Rows Fast with Materialized Views", YouTube video, June 2020.
- Chris Saxon, "[Oracle] (Perf 5/9) Why Isn't My Query Using an Index?", YouTube video, June 2020.
- Chris Saxon, "[Oracle] (Perf 4/9) How to Create Database Indexes", YouTube video, June 2020.
- Chris Saxon, "[Oracle] (Perf 3/9) What to Look for in Execution Plans", YouTube video, June 2020.
- Chris Saxon, "[Oracle] (Perf 2/9) What are Optimizer Statistics?", YouTube video, June 2020.
- Chris Saxon, "[Oracle] (Perf 1/9) How to Read an Execution Plan", YouTube video, May 2020.
- Chris Saxon, "[Oracle] The Purpose of the DUAL Table", YouTube video, Sep 2018.
- Chris Saxon, "[Oracle] Optimizing SQL Performance", YouTube video, July 2018.
- Chris Saxon, Hans Viehmann, "Advanced SQL - Graph Traversal Problems", YouTube video, July 2019.
- Bert Scalzo, "Common SQL Patterns to Avoid for Best Performance", PASS Data Community Summit Talk, 2021.
- Mickey Stuewe, "Changing Your Habits to Improve the Performance of Your T-SQL", YouTube video, 2014.
- Robert Treat, "I Didn't Know Postgres Could Do That", Postgres Open talk, 2019.
- Markus Winand, "Modern SQL: Evolution of a Dinosaur", JavaZone talk, 2018.
- Markus Winand, "Modern SQL: A Lot has Changed since SQL-92", Voxxed Days Vienna talk, 2018.
- Markus Winand, "SQL in the 21st Century", Voxxed Days Bucharest talk, 2017.
Websites:
- LearnSQL.com Cheat Sheet -- Basics
- LearnSQL.com Cheat Sheet -- Functions
- LearnSQL.com Cheat Sheet -- Joins
- LearnSQL.com Cheat Sheet -- Window Functions
- Oracle Latest Features Table
- asktom.oracle.com
- Statistics Parser (to better format SQL Server stats)
- pgPedia.info
- DB-Engines.com
- Modern-SQL.com
- sql-workbench.eu/dbms_comparison.html
- https://en.wikipedia.org/wiki/Comparison_of_relational_database_management_systems
- Free Online SQL Playgrounds: DB Fiddle DB Fiddle UK SQL Fiddle SQL Test
- Tim Mitchell, "SSMS Tip: Regular Expressions in SSMS", Blog Article, Dec 2019.
- Tim Mitchell, "SSMS Tip: Beep when Query Completes", Blog Article, Dec 2019.
- Tim Mitchell, "SSMS Tip: Vertical Text Selection", Blog Article, Dec 2019.
- Guilhem Bichot, "A New, Simple Way to Figure Out Why Your Recursive CTE (rCTE) is Running Away", MySQL Server blog entry, Jan 2020.
- Jonathan S. Katz, "[CTE] WITH Queries: Present & Future", Blog Entry, Feb 2019.
- Terence Zekveld, "Introduction to CTE's", PostgresConf South Africa talk, 2018.
- Haki Benita, "Be Careful with CTE in PostgreSQL [version 11 and older]", Blog entry, Sep 2018.
- Aldo Zelen, "Simplify SQL Code: Recursive Queries (AKA CTE's)", Blog Article, Dec 2017.
- Aldo Zelen, "Long SQL Query vs. Recursive CTE (rCTE)", Blog Article, Oct 2017.
- BeardedDev, "CTE's", YouTube video, 2017.
- Jonathan Kehayias, "[Perf] CTE's, Window Functions, and Views", Blog entry, Jan 2013.
- Tim Hall, "[CTE] WITH Clause: Subquery Factoring in Oracle 9.2", Oracle-Base article, June 2007.
- Chris Saxon, "[Oracle] Visualizing SQL Window Functions", YouTube video, Jan 2022.
- Kathi Kellenberger, "T-SQL Window Function Performance", YouTube video, 2021.
- Willem Booysen, "Window Functions", PostgresConf South Africa talk, 2018.
- BeardedDev, "Window Functions", YouTube video, 2017.
- Lukas Eder, "LATERAL Is Your Friend to Create Local Column Variables in SQL", Blog entry, Nov 2022.
- Rob Reid, "LATERAL JOIN's", Blog entry, Aug 2021.
- Hans-Jürgen Schönig, "Understanding LATERAL JOIN's in PostgreSQL", CYBERTEC Article, July 2021.
- Yash Sanghvi, "The Powerful LATERAL JOIN in PostgreSQL", Blog entry, June 2021.
- Ben Brumm, "SQL CROSS APPLY and OUTER APPLY: The Complete Guide", Article, April 2021.
- Amanda Sposito, "[Perf] Postgres' LATERAL JOIN, Have You Heard About It?", Blog Entry, Jan 2021.
- PopSQL Team, "How to Use LATERAL JOIN's in PostgreSQL", Article, Oct 2020.
- Steve Pousty, "Iterators in PostgreSQL with LATERAL Joins", Blog Entry, Aug 2020.
- Guilhem Bichot, "Supporting All Kinds of Outer References in Derived Tables
(Lateral or not)", MySQL Server blog entry, July 2019.
- Norvald H. Ryeng, "LATERAL Derived Tables in MySQL", FOSDEM talk, 2019.
- Guilhem Bichot, "Support for LATERAL Derived Tables Added to MySQL 8.0.14", MySQL Server blog entry, Jan 2019.
- Aldo Zelen, "Useful SQL Patterns: Pivoting", Blog Article, July 2017.
- Itzik Ben-Gan, "Boost Your T-SQL with the APPLY Operator (Module 1)", MS Virtual Academy session, Jan 2014.
- Itzik Ben-Gan, "Boost Your T-SQL with the APPLY Operator (Module 2)", MS Virtual Academy session, Jan 2014.
- Vidal Ekechukwu, "LATERAL JOIN's", PG Cast, June 2016.
- Graeme Malcolm & Geoff Allix, "[T-SQL] Using Subqueries and APPLY's", MS Virtual Academy session, Jan 2016.
- Tim Hall, "LATERAL Inline Views, CROSS APPLY and OUTER APPLY Joins in Oracle 12.1", Oracle-Base article, June 2015.
- Dan Robinson, "PostgreSQL's Powerful New Join Type: LATERAL's", Blog entry, Dec 2014.
- Itzik Ben-Gan, "Creative Uses of the APPLY Operator (Session 1)", Swedish SQL Server User Group session, Jan 2014.
- Itzik Ben-Gan, "Creative Uses of the APPLY Operator (Session 2)", Swedish SQL Server User Group session, Jan 2014.
- Jeff Smith, "Taking a Look at CROSS APPLY", Blog entry, Oct 2007.
- Jeff Smith, "Returning Complex Data from User-Defined Functions with CROSS APPLY", Blog entry, June 2007.
- Sureshkumar Ramakrishnan, "New T-SQL Features in SQL Server 2005 Part 2 [includes CROSS APPLY and OUTER APPLY]", Blog entry, Dec 2006.
- Bill Graziano, "Using CROSS APPLY in SQL Server 2005", Blog entry, May 2005.
- Paul Ramsey, "Rise of the Anti-Join", Blog Entry, Aug 2022.
- Lukas Eder, "A Quick and Dirty Way to Concatenate Two Vaguely Related Tables in SQL", Blog Entry, May 2022.
- David Christensen, "Postgres Query Optimization: LEFT JOIN vs UNION ALL", Crunchy Data blog entry, May 2022.
- Chris Saxon, "[Oracle] Visualizing SQL Joins", YouTube video, Oct 2021.
- Kateryna Koidan, "How to Join Only the First Row in SQL", Blog Entry, Oct 2021.
- Lukas Eder, "Use NATURAL FULL JOIN to Compare Two Tables in SQL", JOOQ blog entry, Aug 2020.
- Kateryna Koidan, "Practical Examples of When to Use Non-Equi JOINs in SQL", Blog Entry, June 2020.
- Dorota Wdzięczna, "Subquery vs. JOIN", Blog Article, May 2020.
- Guilhem Bichot, "A Must-Know about NOT IN in SQL -- More Anti-Join Optimization", MySQL Server blog entry, Feb 2020.
- Sisense Data Team, "4 Ways to Join Only the First Row in SQL", Sisense Blog Entry, Jan 2020.
- Brian Davis, "[PostgreSQL] Cost of a Join - Part 2: Enums, Wider Tables", Blog Article, Sep 2018.
- Brian Davis, "[PostgreSQL] Cost of a Join", Blog Article, Aug 2018.
- Dorota Wdzięczna, "An Illustrated Guide to Multiple Join", Blog Article, Sep 2017.
- Dorota Wdzięczna, "An Illustrated Guide to the SQL Non Equi Join", Blog Article, Sep 2017.
- Dorota Wdzięczna, "An Illustrated Guide to the SQL Self Join", Blog Article, Sep 2017.
- Dorota Wdzięczna, "An Illustrated Guide to the SQL OUTER JOIN", Blog Article, Aug 2017.
- Dorota Wdzięczna, "An Illustrated Guide to the SQL CROSS JOIN", Blog Article, July 2017.
- Dorota Wdzięczna, "An Illustrated Guide to the SQL INNER JOIN", Blog Article, July 2017.
- Alex Petralia, "More Dangerous Subtleties of JOINs in SQL", Blog Entry, July 2017.
- Lukas Eder, "A Probably Incomplete, Comprehensive Guide to the Many Different Ways to JOIN tables in SQL", JOOQ blog entry, Jan 2017.
- Lukas Eder, "Say NO to Venn Diagrams when Explaining JOINs", JOOQ blog entry, July 2016.
- Graeme Malcolm & Geoff Allix, "[T-SQL] Querying Multiple Tables with JOIN's", MS Virtual Academy session, Jan 2016.
- Alexander Polishchuk, "[Oracle] Contiguous Data Range via FULL OUTER JOIN's", Database Journal article, March 2013.
- Baron Schwartz, "Two Subtle Bugs in OUTER JOIN Queries", Blog Entry, Aug 2010.
- James Standen, "Inner and Outer Joins, SQL Examples & The Join Block", Datamartist Blog Entry, Feb 2010.
- Baron Schwartz, "The Dangerous Subtleties of LEFT JOIN and COUNT() in SQL", Blog Entry, April 2009.
- William McEvoy, "T-SQL 101, Lesson 5: How to Join Tables", SQL Server Magazine, 10 (7), July 2008, pages 33-36.
- Baron Schwartz, "How to Understand SQL Joins", Blog Entry, Oct 2005.
- Marija Ilic, "How to Track Down Duplicate Values in a Table", Blog Article, Sep 2017.
- Sumit Agarwal, "SQL Server - OLTP vs. OLAP", SQLWizard Blog entry, March 2020.
- Troels Arvin, "Comparison of different SQL implementations"
- Itzik Ben-Gan, "Enhancing PIVOT for Crosstab Queries: Learn 6 Ways to Work Around PIVOT's Limitations", SQL Server Magazine, 8 (12), Dec 2006, pages 17-20.
- Haki Benita, "12 Common Mistakes and Missed Optimization Opportunities in SQL", Blog entry, Nov 2019.
- Aaron Bertrand, "Bad Habits: Avoiding NULL in SQL Server", SQL Performance blog entry, Oct 2021.
- Guilhem Bichot, "New and Old Ways to CHECK constraints, DOMAIN", MySQL Server blog entry, Feb 2016.
- Alex Bolenok, "10 Things in SQL Server (Which Don't Work as Expected)", TechPro Article, July 2013.
- Rob Collie, "I Know SQL Queries, So Why Do I Need Power Pivot?", P3 Adaptive Blog entry, Sep 2014.
- Lukas Eder, "Changing SELECT .. FROM into FROM .. SELECT Does Not 'Fix' SQL", Blog Entry, May 2022.
- Lukas Eder, "How to Get an RDBMS Server Version with SQL", Blog Entry, May 2021.
- Lukas Eder, "Implementing a Generic REDUCE Aggregate Function with SQL", JOOQ blog entry, Feb 2021.
- Lukas Eder, "How to Write a Multiplication Aggregate Function in SQL", JOOQ blog entry, Sep 2018.
- Lukas Eder, "How to Write Efficient TOP-N Queries in SQL", JOOQ blog entry, Sep 2017.
- Lukas Eder, "How To Calculate Multiple Aggregate Functions in a Single
Query", JOOQ blog entry, April 2017.
- Lukas Eder, "A Beginner's Guide to the True Order of SQL Operations", JOOQ blog entry, Dec 2016.
- Lukas Eder, "When to Choose SQL and When to Choose NoSQL", JOOQ blog entry, Sep 2016.
- Lukas Eder, "10 SQL Tricks that You Didn't Think were Possible", JOOQ blog entry, April 2016.
- Lukas Eder, "3 Reasons Why It's Okay to Stick with SQL", JOOQ blog entry, March 2015.
- Lukas Eder, "How to Create a Range from 1 to 10 in SQL", JOOQ blog entry, Nov 2013.
- Denis Gobo, "Sort Values Ascending but NULL's Last", SQLblog.com blog entry, Oct 2007.
- Victor Sánchez Jáuregui, "Power Query or SQL Server? Which, When and Why", SQLServerCentral Blog entry, Jan 2021.
- Jonathan S. Katz, "Better Range Types in PostgreSQL 14: Turning 100 Lines of SQL into 3", Blog Entry, June 2021.
- Evan Klitzke, "The Commodification of Databases", Blog entry, Aug 2015.
- Chris Komlenic, "8 Reasons Why MySQL's ENUM Data Type is Evil", Blog entry, March 2011.
- Teo Lachev, "T-SQL, Power Query, or DAX?", Prologika Blog Entry, Jan 2019.
- Greg Low, "Think that VARCHAR(10) Means 10 Characters? If so, Think Again...", Blog entry, July 2019.
- Kristian Nielsen, "Selecting Rows Holding Group-wise Maximum of a Field, Part 2", Blog entry, Nov 2008.
- Kristian Nielsen, "Selecting Rows Holding Group-wise Maximum of a Field", Blog entry, Nov 2008.
- Duong Nguyen, "PostgreSQL's ENUM is no Silver Bullet: 4 Ways to do Inclusion Validations", Article, July 2020.
- Alex Petralia, "Why Data Analysts Should Exercise Caution When Taking Averages (Part 2)", Blog Entry, April 2017.
- Alex Petralia, "Why Data Analysts Should Exercise Caution When Taking Averages (Part 1)", Blog Entry, April 2017.
- PopSQL Team, "How to Compare Two Values When One is NULL in PostgreSQL [using IS DISTINCT FROM ]", Article, Oct 2020.
- Steve Pousty, "Replacing Lines of Code with 2 Little Regex's in PostgreSQL", Blog Entry, Dec 2020.
- Paul Ramsey, "Extracting and Substituting Text with Regular Expressions in PostgreSQL", Blog Entry, Dec 2021.
- Paul Ramsey, "Fuzzy Name Matching in PostgreSQL", Blog Entry, Feb 2021.
- David Rowley, "Speeding Up Sort Performance in Postgres 15", MS blog entry, May 2022.
- Baron Schwartz, "If Yoda You Were, SQL You Would Invent", Blog Entry, Feb 2013.
- Baron Schwartz, "My Wishlist for SQL: The UNTIL Clause", Blog Entry, Jan 2010.
- Baron Schwartz, "Why NULL Never Compares to False to Anything in SQL", Blog Entry, May 2006.
- Baron Schwartz, "How to Avoid Many-to-One Problems in SQL", Blog Entry, Mar 2006.
- Paul Turley, "SQL, M or DAX?", Blog Entry, May 2018.
Best viewed at
1280x720 (720p) screen resolution or higher.