What is the most magical and mesmerizing code you have ever seen?

What is the most magical and mesmerizing code you have ever seen? by Tim Boudreau

Answer by Tim Boudreau:

The bit of SQL in this defunct article (internet archive version linked), accurately described as “one of the great mind-blowing SQL queries”:

SELECT s1.article, s1.dealer, s1.price
FROM shop s1
LEFT JOIN shop s2 ON s1.article = s2.article AND s1.price < s2.price
WHERE s2.article IS NULL;

At a glance, you think it would return nothing every time. But no. And like a zen koan, once you understand what it does, and why it does what it does, you gain enlightenment – a deeper understanding of what SQL really is, how it relates to set theory and why that matters if you want to master it.

What is the most magical and mesmerizing code you have ever seen?

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s