---
title: "SQL Join vs Subquery: The Game Changer"
url: https://daily.dev/posts/sql-join-vs-subquery-the-game-changer-zjorxmruy
source_url: https://daily.dev/posts/sql-join-vs-subquery-the-game-changer
type: article
source: "daily.dev"
author: "Ido Shamun"
published: 2020-11-19T14:25:07.236Z
updated: 2021-10-07T14:17:10.317Z
tags: ["sql"]
upvotes: 12
comments: 3
language: 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.

# SQL Join vs Subquery: The Game Changer

**[daily.dev](https://daily.dev/sources/daily)** · [@idoshamun](https://daily.dev/idoshamun) · 12 upvotes · 3 comments

## Summary

Using Postgres' JSON capabilities, we can create queries that will make you feel like you're using MongoDB. The inner select creates a result set that stores the newest 3 comments for every post in the main query. The aggregate function turns N rows into a real JSON array.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://daily.dev/posts/sql-join-vs-subquery-the-game-changer>

## Community discussion

Top comments from developers on daily.dev.

**@pmcgovern** · 2 upvotes

> Definitely an interesting approach that on the surface looks compelling. I'd love to see benchmarks in large datasets (5m rows+) in a high-throughput environment pitting this approach vs joins (which would return separate rows for each comment) or running two separate queries.
> There's also the piece of this that requires custom mapping type implementation in major ORMs (ex: Doctrine, Eloquent) to take advantage or RDBMS specific functionality. Fortunately, that piece isn't as painful as it used to be. Regardless, this is great food for thought!

**@idoshamun** · 1 upvotes

> This is truly an endless debate... I usually use JOINs but sometimes subqueries make more sense. Let me know what you think 🙌

## Similar posts on daily.dev

- [Don’t just attend KubeCon \+ CloudNativeCon, Merge Forward your experience\!](https://daily.dev/posts/don-t-just-attend-kubecon-cloudnativecon-merge-forward-your-experience--l0rpp73x8) · CNCF · 0 upvotes · 0 comments
- [Announcing H2 2026 KCDs](https://daily.dev/posts/announcing-h2-2026-kcds-m96goajm1) · CNCF · 1 upvotes · 0 comments
- [Two months of Open Community Groups](https://daily.dev/posts/two-months-of-open-community-groups-asf52zhbs) · CNCF · 0 upvotes · 0 comments
- [CNCF Unveils Schedule for KubeCon \+ CloudNativeCon Europe 2026](https://daily.dev/posts/cncf-unveils-schedule-for-kubecon-cloudnativecon-europe-2026-ikhcoa5cb) · CNCF · 2 upvotes · 0 comments
- [CNCF Debuts KubeCon \+ CloudNativeCon Japan 2026 Schedule](https://daily.dev/posts/cncf-debuts-kubecon-cloudnativecon-japan-2026-schedule-xp5pyudub) · CNCF · 1 upvotes · 0 comments

---

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

[View this post on daily.dev](https://daily.dev/posts/sql-join-vs-subquery-the-game-changer-zjorxmruy)
