~/devreads

#cross apply

4 posts

4 Nov 2022

lukaseder 1 min read

The standard SQL WITH clause has been tremendously helpful in structuring SQL queries. Instead of nesting everything in unreadable derived tables like this: People have started moving the logic up front, just like in any other programming language, where we declare things first, lexically, then use them: Both queries will produce the 5 actors with … Continue reading LATERAL is…

sqlapplycross applycross join laterallateral

14 May 2018

lukaseder 1 min read

Google’s BigQuery has a very interesting SQL language feature, which I’ve missed many times in other databases: select: SELECT [{ ALL | DISTINCT }] { [ expression. ]* [ EXCEPT ( column_name [, ...] ) ] [ REPLACE ( expression [ AS ] column_name [, ...] ) ] | expression [ [ AS ] alias … Continue reading Selecting all…

sqlcross applynested recordspostgresqlprojection

22 Sept 2017

lukaseder 1 min read

A very common type of SQL query is the TOP-N query, where we need the “TOP N” records ordered by some value, possibly per category. In this blog post, we’re going to look into a variety of different aspects to this problem, as well as how to solve them with standard and non-standard SQL. These … Continue reading How to…

sqlcross applylateral joinouter applyrank

26 Oct 2015

lukaseder 1 min read

I’ve stumbled upon this very interesting question on Stack Overflow, recently. Its title is: [How to] compare a number with sum of subset of numbers In this article, we’ll compare the user’s imperative approach to the extremely elegant (Oracle) SQL approach. We’ll be making use of any combination of these awesome SQL features: Window functions … Continue reading How to…

sqlcommon table expressionscross applydense rankfirst