---
title: "Discussion on \"Optimizing SQL: Sometimes It’s About the Data, Not Just the Query\" | Hashnode"
description: "Discussion on \"Optimizing SQL: Sometimes It’s About the Data, Not Just the Query\". I recently came across a LinkedIn post where someone used two CTEs to pull DISTINCT merchant_ids from the same table—split by year—and then joined everything back to the orders table. It worked! But it got me thinking. Sometimes, the real challenge i..."
url: "https://hashnode.com/posts/optimizing-sql-sometimes-its-about-the-data-not-just-the-query/67dfa329b7863931acbfeee5"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Optimizing SQL: Sometimes It’s About the Data, Not Just the Query](https://sqljournal.hashnode.dev/optimizing-sql-sometimes-its-about-the-data-not-just-the-query?utm_source=hashnode&utm_medium=feed)

I recently came across a LinkedIn post where someone used two CTEs to pull DISTINCT merchant\_ids from the same table—split by year—and then joined everything back to the orders table. It worked! But it got me thinking. Sometimes, the real challenge i...

Mar 23, 2025 · 5 min read · sqljournal.hashnode.dev  
Updated Mar 28, 2025  
Read the article

-   [#sql](https://hashnode.com/tag/sql)
-   [#data-quality](https://hashnode.com/tag/data-quality)
-   [#data-architecture](https://hashnode.com/tag/data-architecture)
-   [#postgresql](https://hashnode.com/tag/postgresql)
-   [#python](https://hashnode.com/tag/python)
-   [#database-administration](https://hashnode.com/tag/database-administration)

## Written by

[John M Harper](https://hashnode.com/@j79h110)

@j79h110

  
[View profile](https://hashnode.com/@j79h110)

Principal Level Database Administrator

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
