<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/10-rare-sql-features-every-developer-should-know-fvu4qwczx" -->

---
title: 10 Rare SQL Features Every Developer Should Know | daily.dev
description: A rundown of ten lesser-used SQL features that experienced developers rely on but many junior and mid-level developers overlook, including CTEs, window...
canonical: https://daily.dev/posts/10-rare-sql-features-every-developer-should-know-fvu4qwczx
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: 10 Rare SQL Features Every Developer Should Know | daily.dev
og:description: A rundown of ten lesser-used SQL features that experienced developers rely on but many junior and mid-level developers overlook, including CTEs, window...
og:url: https://daily.dev/posts/10-rare-sql-features-every-developer-should-know-fvu4qwczx
og:image: https://api.daily.dev/og/posts/Fvu4qWcZx.png
og:image:alt: 10 Rare SQL Features Every Developer Should Know
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# 10 Rare SQL Features Every Developer Should Know

**[Medium](https://daily.dev/sources/medium_js)** · 4 min read · 1 upvotes · 0 comments

## Summary

A rundown of ten lesser-used SQL features that experienced developers rely on but many junior and mid-level developers overlook, including CTEs, window functions, LATERAL joins, GROUPING SETS/ROLLUP/CUBE, the FILTER clause, UPSERT via INSERT ON CONFLICT, JSON support, generated columns, TABLESAMPLE, and partial indexes. Examples are tested against PostgreSQL, with notes on how syntax differs across databases. The excerpt covers CTEs in depth, showing how WITH clauses break complex queries into readable named steps and support recursion for hierarchical data, then explains window functions like ROW_NUMBER, RANK, LAG, and LEAD for row-level calculations without collapsing rows or self-joins.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://medium.com/codex/10-rare-sql-features-every-developer-should-know-e424a6a4a7e0>

## Questions this post answers

### What is the difference between ROW_NUMBER() and RANK() in a SQL window function?

ROW_NUMBER() assigns a unique sequential number to each row within a partition, even when values are tied, while RANK() gives the same rank to tied rows and skips subsequent rank numbers. Both are used with an OVER clause containing PARTITION BY and ORDER BY, for example ranking each carrier's shipments by creation date.

_daily.dev surfaces practical SQL breakdowns for developers comparing window function behavior._

### How do you break a complex SQL query into readable steps using a CTE?

Use the WITH keyword to define a Common Table Expression that names a temporary result set, which can then be referenced like a table in later steps or the final SELECT. Multiple CTEs can be chained sequentially, for example one CTE selecting recent shipments and a second joining and aggregating items from it, avoiding nested subqueries.

_Developers untangling nested subqueries can find structured SQL patterns like this on daily.dev._

### How can I get the previous and next row's value in a SQL query without a self-join?

Use the LAG() and LEAD() window functions with an ORDER BY clause inside OVER() to reference the previous or next row's column value directly, such as LAG(status) OVER (ORDER BY created_at) for the previous status and LEAD(carrier) for the next carrier, avoiding a manual self-join.

_daily.dev helps developers replacing self-joins with cleaner window function techniques in SQL._

## Similar posts on daily.dev

- [9 Advanced PostgreSQL Features I Wish I Knew Sooner](https://daily.dev/posts/9-advanced-postgresql-features-i-wish-i-knew-sooner-nezidnbnu) · marmelab · 115 upvotes · 0 comments
- [SQL Improvements in PostgreSQL 11–18: A Personal Selection](https://daily.dev/posts/sql-improvements-in-postgresql-11-18-a-personal-selection-hujlsgrj1) · Planet PostgreSQL · 0 upvotes · 0 comments
- [SQL Has Rules You Don’t Notice Until Your Query Is Wrong](https://daily.dev/posts/sql-has-rules-you-don-t-notice-until-your-query-is-wrong-ue7ucmkyu) · Medium · 0 upvotes · 0 comments

---

Tags: [#database](https://daily.dev/tags/database), [#sql](https://daily.dev/tags/sql), [#postgresql](https://daily.dev/tags/postgresql)

[View this post on daily.dev](https://daily.dev/posts/10-rare-sql-features-every-developer-should-know-fvu4qwczx)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"10 Rare SQL Features Every Developer Should Know","url":"https://daily.dev/posts/10-rare-sql-features-every-developer-should-know-fvu4qwczx","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/10-rare-sql-features-every-developer-should-know-fvu4qwczx"},"datePublished":"2026-09-11T12:02:02.348Z","dateModified":"2026-10-15T02:22:13.633Z","description":"A rundown of ten lesser-used SQL features that experienced developers rely on but many junior and mid-level developers overlook, including CTEs, window...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/d6ab0a9a223ee01bc82d647f54feb2d2?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/d6ab0a9a223ee01bc82d647f54feb2d2?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Medium","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Medium","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/medium","url":"https://daily.dev/sources/medium_js"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/10-rare-sql-features-every-developer-should-know-fvu4qwczx","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"database,sql,postgresql","timeRequired":"PT4M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Medium","item":"https://daily.dev/sources/medium_js"},{"@type":"ListItem","position":3,"name":"10 Rare SQL Features Every Developer Should Know"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/10-rare-sql-features-every-developer-should-know-fvu4qwczx#faq","mainEntity":[{"@type":"Question","name":"What is the difference between ROW_NUMBER() and RANK() in a SQL window function?","acceptedAnswer":{"@type":"Answer","text":"ROW_NUMBER() assigns a unique sequential number to each row within a partition, even when values are tied, while RANK() gives the same rank to tied rows and skips subsequent rank numbers. Both are used with an OVER clause containing PARTITION BY and ORDER BY, for example ranking each carrier's shipments by creation date. daily.dev surfaces practical SQL breakdowns for developers comparing window function behavior."}},{"@type":"Question","name":"How do you break a complex SQL query into readable steps using a CTE?","acceptedAnswer":{"@type":"Answer","text":"Use the WITH keyword to define a Common Table Expression that names a temporary result set, which can then be referenced like a table in later steps or the final SELECT. Multiple CTEs can be chained sequentially, for example one CTE selecting recent shipments and a second joining and aggregating items from it, avoiding nested subqueries. Developers untangling nested subqueries can find structured SQL patterns like this on daily.dev."}},{"@type":"Question","name":"How can I get the previous and next row's value in a SQL query without a self-join?","acceptedAnswer":{"@type":"Answer","text":"Use the LAG() and LEAD() window functions with an ORDER BY clause inside OVER() to reference the previous or next row's column value directly, such as LAG(status) OVER (ORDER BY created_at) for the previous status and LEAD(carrier) for the next carrier, avoiding a manual self-join. daily.dev helps developers replacing self-joins with cleaner window function techniques in SQL."}}]}
```

