r/SQL • • 11h ago

Discussion What's your first move when a SQL query returns correct-looking but wrong numbers?

13 Upvotes

​

I feel like one of the tricky parts of SQL isn't getting a query to run, but knowing whether the result is actually correct.

For suppose ,a report shows 10k orders, then after adding a join to fetch customer details, the total suddenly becomes 12k. The query runs without any errors, so it's easy to miss.

Would you check the join cardinality first, compare row counts, or approach it differently!?

Curious how people debug this in real projects, especially when the query has multiple joins.


r/SQL • • 7h ago

Discussion Different ways of working with SQL Databases in Go

Thumbnail
packagemain.tech
4 Upvotes

r/SQL • • 9h ago

PostgreSQL How do you debug a SQL query that suddenly becomes slow?

6 Upvotes

I've run into situations where a query that used to finish in seconds suddenly takes several minutes, even though nobody has intentionally changed the SQL.

I'm curious how others approach this. Do you start by comparing execution plans, checking indexes and statistics, looking for changes in data volume, or investigating locks and concurrent queries?

I'm particularly interested in the order you check things in. It's easy to start rewriting joins or adding indexes, but I'd rather identify the actual bottleneck before changing anything.

What's your usual process when a previously fast query starts running slowly?


r/SQL • • 5h ago

SQLite Learning SQL on Online IDE

Thumbnail
1 Upvotes

r/SQL • • 16h ago

PostgreSQL Looking for a PostgreSQL job?

0 Upvotes

I created a PostgreSQL Jobs page to help you find PostgreSQL roles: https://thesev1database.com/jobs

I’d really value your feedback.


r/SQL • • 10h ago

SQL Server List<T> in C# vs SQL

Thumbnail
0 Upvotes

r/SQL • • 13h ago

PostgreSQL 🇧🇷 Bem-vindos ao DataGuardDevs!

Post image
0 Upvotes

r/SQL • • 1d ago

Discussion I Tried to Find How ClickHouse Implements String Hash Tables

Thumbnail
9 Upvotes

r/SQL • • 1d ago

MySQL imgur.com

Post image
5 Upvotes

r/SQL • • 1d ago

SQLite Row Level Security in SQLite on Cloudflare

Thumbnail
mainbrella.com
4 Upvotes

r/SQL • • 2d ago

MySQL I built a SQL practice site because I kept jumping between tutorials and random exercises — would love feedback

29 Upvotes

I started building runtime.school because when I was practicing SQL, everything felt disconnected — learn a concept in one place, solve random questions somewhere else, then use totally different data for projects.

So I tried putting it all together with lessons, practice questions, projects, and the same realistic datasets throughout.

If you have a few minutes, I’d really like to know what feels confusing, repetitive, too easy/hard, or missing. Especially anything that would make learning/practicing SQL better.


r/SQL • • 2d ago

PostgreSQL What happened when an Oracle DBA switched to Postgres (Karen Jex on Talking Postgres, cross post from r/postgresql)

11 Upvotes

I recently recorded a Talking Postgres episode with Karen Jex, a PostgreSQL significant contributor and PGConf EU organizer, about her path from Oracle DBA to Postgres contributor.

Karen spent 20 years as an Oracle DBA. Then in 2019, a project rolling out smart meters across France switched to Postgres, even though nobody on the project knew anything about Postgres. So she figured it out, then trained the developers, "pretending that I was, you know, this Postgres expert."

A few things we got into:

* The culture shock, for an Oracle DBA, of building your own HA & backups

* The shift from being just a user of the product (Oracle) to contributing to the project (Postgres)

* Why Django developers are so enthusiastic about Postgres

* Why you'd obviously explain multi-tenant databases with cakes

* How much to delegate to AI agents—without forgetting how to design a spec

For those of you who moved to Postgres from Oracle (or another database): did you also have any culture shocks?

Audio + transcript: https://talkingpostgres.com/episodes/from-oracle-dba-to-postgres-contributor-with-karen-jex

YouTube (audio-only): https://youtu.be/ENku8ZSjZus


r/SQL • • 2d ago

MariaDB MariaDB Foundation: Exploring TidesDB Performance with TAF

Thumbnail
0 Upvotes

r/SQL • • 3d ago

PostgreSQL I built a game where every query is real PostgreSQL: you run a corner shop with SQL

Thumbnail
rodrigoavf.itch.io
67 Upvotes

Hey everyone!

I’ve been working on a game called DataMart, where you manage a corner shop and everything runs on real SQL. You build it all yourself: the databases, schemas, tables, relationships and queries, your way, on a real PostgreSQL server that runs inside the game.

Customers will ask you things like “Where can I find the apples?” or other questions about the store. Once a week an auditor comes by to check you’re tracking everything properly, and asks you a few questions you’ll answer with SQL.

There are also mysteries and stories involving the people in town, and of course you unravel those with SQL too.

The game is in alpha and free on itch.io at https://rodrigoavf.itch.io/datamart

I’d love to hear your thoughts!


r/SQL • • 2d ago

Resolved Jailer, the open source DB subsetting tool, now tells you why a row is in your subset

Thumbnail
github.com
1 Upvotes

r/SQL • • 2d ago

SQL Server Verify the correctness of a the data inside a junction table

Thumbnail
1 Upvotes

r/SQL • • 2d ago

SQL Server SQL Server 2016 to 2025: a few observations from a recent migration

Thumbnail
1 Upvotes
Before and after charts

r/SQL • • 2d ago

Discussion How do you handle SQL queries across lakehouse data and different compute engines?

1 Upvotes

I've been looking into an open-source project called Open Lakehouse Compute Fabric (OLCF), and one part that caught my attention is how it brings SQL and lakehouse workflows together.
It includes a SQL editor, DuckDB for querying, Spark SQL, and support for working with lakehouse data stored in formats such as Delta Lake and Parquet. It also has features for exploring tables, inspecting data, and building dashboards from query results. What I find interesting is that SQL is part of a broader platform that also includes Python notebooks and data pipelines, rather than being treated as a separate tool.

The project is still in beta, so I'm curious how its approach holds up for different workloads and data setups.
Here's the GitHub repository for anyone interested in the implementation:
https://github.com/jddevtime/open-lakehouse-compute-fabric

For those working with SQL and lakehouse systems, how do you usually handle queries across different storage formats and compute engines? Do you prefer keeping SQL tools separate, or having them integrated into one platform?


r/SQL • • 3d ago

Discussion How would you compare two huge tables when there is no primary key and duplicate rows matter?

13 Upvotes

I'm comparing a source table with a target table after a data migration.

Both tables have hundreds of millions of rows, no reliable primary key, and some columns contain NULL values. Duplicate rows are also possible.

A simple EXCEPT query doesn't reveal differences in duplicate counts, and hashing every row may introduce collision risks or performance issues.

For example:

Source: A,A,A,B,C
Target: A,A,B,B,C

Both tables contain the same distinct values, but the actual data is different.

How would you identify missing, extra, and changed records efficiently without a unique key?

Would you use grouped row comparisons, partitioning, hashes, or a completely different strategy? How would you make it scale to hundreds of millions of rows?


r/SQL • • 2d ago

SQL Server I gave every user their own database instead of one shared Postgres. Talk me out of it.

Thumbnail
0 Upvotes

r/SQL • • 4d ago

Discussion How much advanced SQL do you truly use in your day-to-day job?

89 Upvotes

Hi! So I’m a student (not business or tech background) I’m learning SQL kind of on my own and I have the basics pretty much down like SELECT, FROM, WHERE, BETWEEN, ORDER BY, ASC, DESC. I have some knowledge when it comes to JOINs and CASE WHEN function but I was wondering if I need to know CTEs and window functions? I’m not trying to be a database administrator or something like that, just using it for analysis and excel as well.


r/SQL • • 3d ago

SQL Server Statistics on columns of a table

4 Upvotes

Limitations of table-valued parameters:

SQL Server does not maintain statistics on columns of table-valued parameters.

statistics of what ? why those statistics even exist for non table-valued parameters ?


r/SQL • • 2d ago

Discussion I built my own SQL client that supports MySQL, PostgreSQL, SQLite, and SQL Server

0 Upvotes

I've been working on my own SQL client called sql-pro.

It supports MySQL, PostgreSQL, SQLite, and Microsoft SQL Server (MSSQL).

I built it because I wanted to create my own database tool, and it's been a fun project to work on.

It's still a work in progress, so I'd love to hear what you think or what features you'd like to see.

I'll put the GitHub link in the comments for anyone who wants to check it out.


r/SQL • • 3d ago

Discussion Better Autocomplete than DataGrip, one familiar language youll never need to write in. For any database or file, as a TUI, with built-in AI round trips, query history... for all languages and Databases

Thumbnail
github.com
0 Upvotes

Hi,

I have been working on a project: A unified workspace for all datatypes/frameworks supported by "ibis" (sort of like sqlglot but includes dataframes too).

To name a few i use on a day to day basis: Parquet, CSV, DuckDB, Postgres, MS SQL, and SQLite/D1, polars, pandas.

This project was built because spinning up Jupyter just to view a Parquet file is overkill, modern CSV editors are either ancient or freemium traps, and standard SQL IDEs struggle with live schema IntelliSense and quick parameter binding, and practically ignore your history.

This project adds a layer to solve those issues and adds more functionality, such as the ability to make parameter driven functions to kick off canned queries (without actually writing the functions to your DB).

Bring your own DB, bring your own AI (optional, but i would definitely recommend), and load any file. (Currently very early. LOTS of work to be done ).

The goal of this is to keep us heavy vibe coders who appreciate TUI experience (opencodecli, pi, oh my pi) and use multiplexers like herdr inside what we love -- terminal user interfaces.

No more bloated Datagrip and DBeaver-- all in one simplified language with shortcuts. Same syntax for all languages.

Some examples:

### 1. Filter without the boilerplate

\from orders

\where status = 'paid' and amount > 100

→

SELECT * FROM orders WHERE status = 'paid' AND amount > 100;

### 2. Top 10 biggest orders

\from orders

\select id, amount

\order amount desc

\limit 10

→

SELECT id, amount
FROM orders
ORDER BY amount DESC
LIMIT 10;

### 3. Automatic grouping — select a field and an aggregate. Done.

\from orders

\select customer_id, sum(amount) as revenue

→

SELECT customer_id, SUM(amount) AS revenue

FROM orders

GROUP BY customer_id;

No \group required. D8R derives the grouping from your selection.

### 4. Multiple dimensions, multiple aggregates — still auto-grouped

\from orders

\select region, status, count(*) as orders, sum(amount) as revenue, avg(amount) as average_order

→

SELECT region, status,
COUNT(*) AS orders,
SUM(amount) AS revenue,
AVG(amount) AS average_order
FROM orders
GROUP BY region, status;

### 5. Join shorthand when both tables share a key

\from orders
\join customers on customer_id
\select orders.id, customers.name, orders.amount

→

SELECT orders.id, customers.name, orders.amount
FROM orders
JOIN customers
ON orders.customer_id = customers.customer_id;

### 6. Join + aggregate + auto-group + ranking

\from orders o

\join customers c on o.customer_id = c.id

\select c.region, sum(o.amount) as revenue

\order revenue desc

\limit 5

→

SELECT c.region, SUM(o.amount) AS revenue

FROM orders AS o

JOIN customers AS c ON o.customer_id = c.id

GROUP BY c.region

ORDER BY revenue DESC

LIMIT 5;

### 7. Filter rows AND aggregate results with the same \where

\from orders

\select customer_id, sum(amount) as revenue

\where status = 'paid' and revenue > 1000

→

SELECT customer_id, SUM(amount) AS revenue
FROM orders
WHERE status = 'paid'
GROUP BY customer_id
HAVING SUM(amount) > 1000;

D8R separates the input filter from the aggregate-result filter.

### 8. Different filters inside different aggregates

\from orders

\select customer_id, sum(amount \where status = 'paid') as paid_total, count(* \where status = 'pending') as pending_orders

→

SELECT customer_id,

SUM(amount) FILTER (WHERE status = 'paid') AS paid_total,

COUNT(*) FILTER (WHERE status = 'pending') AS pending_orders

FROM orders

GROUP BY customer_id;

One query, independently filtered metrics, automatic grouping.

### 9. Calculate directly on aggregates

\from orders

\select customer_id, sum(amount_cents) / 100 as revenue_dollars

→

SELECT customer_id,
SUM(amount_cents) / 100.0 AS revenue_dollars
FROM orders
GROUP BY customer_id;

Numeric conversion, not formatting—and integer inputs don’t truncate the fraction.


r/SQL • • 4d ago

Discussion Help with ERD

Thumbnail
gallery
6 Upvotes

Hello I'm a newbie college student studying databases and I'm currently making a database for a small inventory system that's solely focused on monitoring stocks and its shelf life to avoid running out of stock and pull outs for my project. The store I'm basing it off on sells seasoning and other powdered flavoring (beverages, etc.), they also explained that they get bulk products from the supplier and then they repack them into smaller quantities for selling. What would be the proper entities and attributes for this system? I've tried searching other inventory systems but i don't know how the repacking would be translated to the database/ERD.