r/SQL • • Mar 30 '26

Discussion I've been stuck on SQL self-joins for 6 months and I'm desperate, what is my mental model missing?

35 Upvotes

I've been struggling with SQL self-joins for about 6 months now and every tutorial I've found has failed me (including AI). They all just slam the query on the screen, run it, and the video ends. Nobody actually explains the mechanics. I already feel stupid enough so please be patient with me.

What I do understand:

  • Self-joins are used for tree/hierarchical structures (like employee-manager)
  • Reversing the ON condition in a normal join (two different tables) doesn't break anything because the table names keep the roles honest
  • In a self-join, reversing the ON condition gives silently wrong results, the query runs fine, but the data is flipped

The classic table everyone uses:

emp_id  name  manager_id
1  Alice  NULL
2  Bob  1
3  Carol  1
4  Dave  2

Query A -- correct:

SELECT e.name AS employee, m.name AS manager
FROM employees e
JOIN employees m ON e.manager_id = m.emp_id

Query B -- reversed, silently wrong:

sqlSELECT e.name AS employee, m.name AS manager
FROM employees e
JOIN employees m ON m.manager_id = e.emp_id

What I've tried to understand:

I know that the ON clause is just a filter over all 16 possible row pairs (4×4). I can manually trace every pair and check which ones survive. That works I always get the right answer when I do it on paper. But I cannot keep drawing 16 rows by hand every time I write a query.

People keep telling me things like:

  • "a manager has many employees but an employee has one manager" -- okay but how does that translate to which side of the = sign each column goes on?
  • "think about the direction of the relationship" -- I stop and think, a manager IS also an employee in this table, so what does direction even mean?
  • "the alias that holds the foreign key is the child" -- I understand foreign keys in normal joins but in a self-referencing table both aliases point to the same table so this still feels circular to me

I'm not looking for an analogy. I want the actual logic. What is everyone else seeing that I'm not?

Left-self join

r/SQL • • Mar 30 '26

PostgreSQL Working on PostgreSQL support in Tabularis just got a big upgrade

Post image
0 Upvotes

Hi guys,

I’m working on Tabularis, an open-source database client built with Rust + React.

https://github.com/debba/tabularis

The goal is to create a fast, lightweight and extensible alternative to traditional database GUIs.

In the latest release we switched the PostgreSQL driver to tokio-postgres, which looks giving better performance than old implementation with SQLX under heavy workloads.

On top of that:

• Better JSON handling with a new inline JSON editor

• Improved type mapping for PostgreSQL specific types

• More responsive query execution

• AI-assisted JSON editing powered by MiniMax

The goal is simple: make working with PostgreSQL feel fast and frictionless, especially when dealing with JSON-heavy schemas.

Still early, but the async driver + improved JSON UX already makes a huge difference.

Curious to hear:What’s your biggest pain when working with PostgreSQL JSON columns?


r/SQL • • Mar 29 '26

Discussion Curious what it's like to extract data from Vibe-Coded applications?

17 Upvotes

Data quality for applications has already fallen off a cliff in the past decade or two as we've moved away from proper normalized backend SQL databases powering applications to under-structured JSON sludge being ubiquitous especially for cloud apps, but I'm very curious what data quality and data backends look like in the era of vibe-coded applications? Has anyone had to build a pipeline into a data warehouse or other ETL setup from a vibe-coded application? What does the data quality and interpretability look like?

I have a hypothesis that the job impacts to the Data Analytics and Data Engineering fields resulting from AI automation of folks' daily tasks will be offset by a further dip in data quality we'll see from vibe-coded applications necessitating more headcount to clean up the mess they create on the data side in order to build proper reporting and analytics, but I want to gather some real life data from professionals who may have experience with this to see if I'm right or missing the mark!

Thank you for contribution to human knowledge, and now if someone asks this question in the future, LLMs can refer to this post potentially.


r/SQL • • Mar 30 '26

Discussion Have you seen a setup like this in real life? 👻

Thumbnail
gallery
0 Upvotes

One password for the whole team. Easy to set up. 😅

What could possibly go wrong?
Have you seen a setup like this in real life? 👻


r/SQL • • Mar 29 '26

PostgreSQL Daily SQL Server to PostGRE Synchronization

2 Upvotes

Looking for recommendations for performing once-daily replication (or synchronization) between an SQL Server (source) and Postgres (sink). The intent is to simply ensure that when a user performs a query or refresh for Postgres data, which is feeding a dashboard, the data is an accurate representation of the data in the SQL Server. This is all taking place on Windows Server 2022.

I found this reddit thread below on performing a similar activity using Debezium, but it is unclear to me if Kakfa is actually required (I'm currently not using Kafka). So my general question is, would Debezium still be the appropriate tool for completing this? Or is the once-daily requirement pointing towards a simpler solution such as a Python script that is run using Task scheduler?

https://www.reddit.com/r/PostgreSQL/comments/1hvff8t/mssql_to_postgre_replication/

https://github.com/debezium/debezium


r/SQL • • Mar 30 '26

SQL Server Technical Interview for a Database class

0 Upvotes

So I am in a bit of a pickle. I have a technical SQL interview for a database class I am taking. It is an online asynchronous course with the professor publishing videos on subject matter. I will be honest, I barely watched the videos and finished all labs and assignments utilizing A.I prompting and generative A.I effectively. However, I have a technical Interview for this class. I know I am not particularly in the right as I have to learn the content but nonetheless I’m not here to argue the morality of that. My question is, What advice do you guys have for the technical interview. It is also in about 2 weeks. If necessary I

can no life studying interview questions and become proficient for that. Just need advice. Thank you


r/SQL • • Mar 29 '26

Discussion Fully local SQL Canvas using DuckDB

7 Upvotes

Hi, I have been working on a local-first data canvas as a side project for over a year now:

There is an infinite canvas where each SQL query is a node that can reference other nodes using FROM node_employees() . It will then get refreshed automatically if its parent changes.

You can try it out here: https://app.dash.builders/. It either runs 100% locally in the browser via DuckDB-WASM, or as a DuckDB community extension, so you can query the nodes even from Python. Happy to get some feedback :)


r/SQL • • Mar 28 '26

MySQL What type of SQL skills do you use as a professional data engineering(or any role where you heavily use SQL skills) everyday? Were there new sql skills you learned on the job(like Subqueries, windowing and CTEs?)

29 Upvotes

I really like to know more insight into how advanced my SQL skillls have to be for the average professional data engineer?


r/SQL • • Mar 28 '26

Discussion Primary Key vs Primary Index (and Unique Constraint vs Unique Index). confused

9 Upvotes

Hey everyone,

I’m trying to properly understand this and I think I might be mixing concepts.

From what I understood:

  • A primary index is just an index, so it helps with faster lookups (like O(log n) with B-tree).
  • A primary key is a constraint, it ensures uniqueness and not null.

But then I read that when you create a primary key, the database automatically creates a primary index under the hood.

So now I’m confused:

  • Are primary key and primary index actually different things, or just two sides of the same implementation?
  • Does every database always create an index for a primary key?
  • When should you explicitly create a unique index instead of a unique constraint?

Thank you!


r/SQL • • Mar 28 '26

Discussion what is your job role? do you spend more time reading or writing sql code?

0 Upvotes

let me know


r/SQL • • Mar 27 '26

SQL Server Friday Feedback for Extended Events! ⚡

2 Upvotes

Hey folks! It's been a hot minute since I've posted, a few important things to share, and then a request.

  • GitHub Copilot in SSMS is now Generally Available in SSMS 22.4.1.

  • We released SSMS 22.4.1 last week and recommend folks update to the latest

    • New features include Group by Schema for all SQL databases
    • Additional export options including Excel (yes, you read that correctly), JSON, XML and markdown.
    • Release notes

Now, many of you know that I like Extended Events (XE) a lot. I've been on a mission for...years...to get folks to use XE instead of Profiler and Trace.

Today's post is *not* about that. 💁‍♀️

Today, I want to understand what XE or Profiler/Trace sessions you create most often. Bonus points if you share some insight into why you are using those sessions. EXTRA bonus points if you provide the T-SQL.

If you're curious, my reasons are two-fold.

1️⃣ Within SSMS we have XEvent Profiler (don't come at me for the name). We offer two sessions in there to make it easy for folks to get started. Maybe we should add more.

2️⃣ We're working on Agent Mode for GitHub Copilot in SSMS, and using copilot to help analyze XE data would be incredibly helpful. From my side, I want to make sure our initial efforts cover the data you're analyzing most often.

Thanks in advance to any of you that take time to respond here. It's been a great couple of weeks with feedback from SQLCon/FabCon and MVP Summit. Obviously, we're not done 🤗


r/SQL • • Mar 26 '26

MySQL What’s your process for validating data after ETL jobs?

24 Upvotes

Curious how others handle this —

After running a pipeline (like MySQL → BigQuery / Snowflake), how do you make sure the data is actually correct?

Do you rely on:

  • row count checks?
  • schema comparison?
  • custom scripts?

Or is there a better way?

Trying to understand real-world practices and pain points here.

Not promoting anything — just learning.


r/SQL • • Mar 26 '26

Discussion best text book for query optimization ?

15 Upvotes

I need a text book for query optimization


r/SQL • • Mar 27 '26

MySQL COBOL O SQL?

0 Upvotes

Buenos días, soy prácticamente novato en el tema.

Tengo la intención de complementar mi cv y aprender.. para porque no en un futuro encontrar alguna oportunidad superadora en lo laboral y economico.

Actualmente trabajo en una empresa del agro, en un puesto que tiene que ver con el uso de sap, excel, analis de cuentas, pagos etc.

Que me recomendarian? COBOL o SQL?


r/SQL • • Mar 26 '26

MySQL [Mission 014] The Schema Architect: Data Modeling Under Fire

Thumbnail reddit.com
0 Upvotes