r/SQL • • May 26 '24

PostgreSQL Should I learn SQL over Python?

2 Upvotes

I have degree in management science , and I feel like learning SQL is close to my diploma more than python , I learned Python I know every topic in python I built some projects with django and flask but I didn't need any of this project in my job in management, If I learn SQL (postgresql) Can help me in the future or maybe can I apply for database jobs?


r/SQL • • Dec 27 '18

SQL Tips/Tricks #2 : Use Joins Instead Of Sub queries

1 Upvotes

Use Joins Instead Of Sub queries

SELECT a.id,
(SELECT MAX(created)
FROM Posts
WHERE author_id = a.id)
AS latest_post FROM authors a

Although sub queries are useful, they often can be replaced by a join, which is definitely faster to execute.

SELECT a.id, MAX(p.created) AS latest_post
FROM authors a
INNER JOIN posts p
ON (a.id = p.author_id)
GROUP BY a.id


r/SQL • • Dec 10 '23

Discussion Trending on GitHub top 10 for the 4th day in a row: Open-source framework for integrating AI models and APIs directly with all major SQL databases

1 Upvotes

It is for building AI (into your) apps easily without complex pipelines and makes your database intelligent.

SuperDuperDB is not another database, but rather making your existing favorite database super-duper (funny name for serious tech), think db = superduper(your-database)

Supported databases: Postgres, MySQL, DuckDB, SQLite, Snowflake, BigQuery and more.

Definitely check it out: https://github.com/SuperDuperDB/superduperdb


r/SQL • • Apr 16 '26

Discussion Has anyone else been burned by a silent schema change? Built a mental model for fixing this, want brutal feedback !

0 Upvotes

A few months ago, a data engineer on our team renamed a column. email → user_email. Clean migration, tested, merged on a Friday.

By Monday, three things had quietly broken:

An ETL pipeline was loading nulls into a feature table

A churn prediction model was training on stale data because the join silently failed

A Spark job was producing wrong aggregates: no error, just wrong numbers

Nobody caught it for 4 days. The rename was one line. The fallout took a week.

The problem nobody talks about

Schema changes are treated as a database problem. But the blast radius extends way beyond the DB, into Python ETL scripts, Spark jobs, pandas DataFrames, sklearn feature pipelines, TypeScript APIs, dbt models. All of these reference column names as plain strings. No compiler catches a renamed column. No linter flags a broken JOIN.

I call these Silent Data Breaks, they don't throw exceptions, they just corrupt your data quietly downstream.

The worst part: the person who renames the column often has no idea these files even exist. The DE doesn't know about the ML engineer's feature pipeline. The ML engineer doesn't know about the TS API. Everyone works in their silo.

What I'm thinking about building

A local tool (no cloud, no data ever leaves your machine) that maps dependencies between your schema and your code. You point it at your repo, it crawls SQL, Python, TypeScript, Jupyter notebooks and builds a graph of what references what.

Before you rename email, you ask it:

"What breaks if I rename users.email?"

And it tells you:

Found 9 files referencing users.email:

etl_pipeline.py:43 — pd.read_sql [high confidence]

ml_features.py:6 — spark.sql [high confidence]

churn_model.ipynb:31 — HuggingFace dataset [high confidence]

users-api.ts:7 — pg.query [high confidence]

analytics.ts:6 — Prisma [high confidence]

... 4 more

With exact line numbers and suggested fixes. Before you deploy, not after.

Questions I'm genuinely unsure about:

Do you actually hit this problem? Is it a daily annoyance or a rare fire drill?

Where does the pain live for you? SQL→Python? Python→ML models? ORM→ raw queries?

Would you trust a static analysis tool for this, or does it feel like it'd have too many false positives?

Is the bottleneck awareness ("I didn't know those files existed") or tooling ("I knew, but checking manually takes too long")?

Would this be more useful as a CLI you run before commits, or something that lives in your IDE?

Not selling anything, not launching anything, genuinely trying to understand if this is a real problem worth solving or something that's already handled by tools I don't know about.


r/SQL • • Jul 14 '24

SQL Server 17 SQL Query Best Practices for Developers

Thumbnail
javarevisited.blogspot.com
0 Upvotes

r/SQL • • May 22 '26

Oracle I built a SQL workspace inside VS Code — saved queries, version history, data compare, session monitor

0 Upvotes

I got tired of switching between VS Code and a separate DB tool every few minutes, so I built SQLLab — a VS Code extension that puts a full SQL workspace inside the editor.

What it does:

  • Connect to SQL Server, PostgreSQL, MySQL, Oracle, SQLite, DuckDB

  • Saved query library with full-text search (search name, description, and the SQL itself)

  • Every save creates a version — diff any two versions side by side

  • Data Compare: run two queries against different DBs and see SAME/DIFFERENT per row and column

  • Session Monitor: see blocked/active sessions, kill them from right-click

  • Batch Run: run multiple saved queries in parallel, track status per script

  • Parameterised SQL with Jinja-style {{ variable }} substitution

  • Schema-aware autocomplete (tables, columns, PKs, indexes)

  • Paginated results — no freezing on large datasets

Still early stage, so I’d really appreciate feedback:
What features are missing?
What would stop you from using it?
What DB workflow annoys you the most today?

​


r/SQL • • Jul 12 '26

Discussion Even a SQL Column Can Traumatize You

1 Upvotes

I just had my one of those "wait... what?" moments while working on AdventureWorks ( PS: Working on my 2nd Project) At start BusinessEntityID totally confused me, I kept thinking it was just an employee ID.

Then I realized it isn't limited to employees at all. It represents everyone, employees, customers, vendors, salespeople, I mean... wow!

It felt confusing at first, but once it clicked, I realized how smart that database design actually is.

In this project I'm keeping everything raw as much as possible, like i have the database, a notebook, a pen, and me with my mind! now think what you can do! i really love this although I just started so... let's see how well it can go on (On my Data Cleaning Phase)


r/SQL • • Dec 29 '23

Discussion Explain SQL vs Excel to an absolute noob

9 Upvotes

I am running a company and helping my friend run his company. I am often being called upon to help people/government representatives with their affairs, thus my profile is growing and I am now thinking about opening consultant/BI analyst company of sorts. I am scouting the market and I see that every position is if not directly IT related, then SQL required. I checked out this thing called SQL and I honestly don`t see how it is different than MS Excel (besides interface, I was looking at MySQL).

Why use SQL over Excel?

This is a question from a guy who is always working with excel, whose administration is working with excel and who made business plans resulting in saving and investing some millions using excel.

Despite that I feel the need to understand it better.


r/SQL • • Feb 26 '25

Discussion Will AI Replace Data Analysts or Make Us Stronger?

0 Upvotes

As a data analyst in a fast-paced startup, I’ve seen how AI is reshaping analytics—automating SQL, spotting trends, and speeding up insights. But does that mean our jobs are at risk? I don’t think so.

AI is great at answering what’s happening, but context is everything. A dashboard can look perfect yet be misleading without deeper analysis. That’s where human intuition and business understanding come in.

Rather than replacing analysts, AI is a force multiplier—handling repetitive tasks so we can focus on strategy and communication. The analysts who learn to work with AI, not against it, will thrive.

Will AI replace us or level us up? Let’s discuss! 👇


r/SQL • • Apr 21 '26

MySQL COUNT() sometimes returns incorrect results

1 Upvotes

Hi, I'm using this query, and it does 95% of what I want, but unfortunately it's counting incorrectly ;)

SELECT e.employee_id, e.employee_name, COUNT(sales.employee_id) AS amount_sales

FROM employees AS e

JOIN stores ON e.store_id=stores.store_id

JOIN sales ON e.employee_id=sales.employee_id

WHERE sales.sale_date<=CURDATE()

GROUP BY e.employee_id, e.employee_name

HAVING COUNT(sales.employee_id)>=5 AND MAX(sales.sale_date) >= CURDATE() - INTERVAL 2 YEAR

ORDER BY e.employee_name;

The problem is that, in theory, an employee can work at multiple stores or locations. If that’s the case, then sales are counted multiple times.

employees

employee_idemployee_namestore_id
1000Mark1
1000Mark2
1001Ben3
1002Susan4

(as you can see Mark works at two different stores)

stores

store_idstore_city
1New York
2Las Vegas
3Miami
4Los Angeles

sales

sale_idsale_dateemployee_id
12026-04-201
22025-05-191
32024-12-122
42025-06-063
52026-02-034

So Mark, with ID 1, has made 2 sales, but the total shown is 4 sales because his second store is accidentally included in the count. If he were working in 3 stores, the total would be 6, and so on.

Mark is listed only once in the results, and that’s how it should be—his sales should be displayed across all locations. But in addition to his sales, at least one of his locations should also be included.

The database structure (in particular employees!) isn’t ideal, but there’s nothing I can do about it.

Should I perhaps work with Views/CTEs and add the store information “at the end,” since it doesn’t affect the calculation anyway?


r/SQL • • Oct 01 '23

SQL Server Someone please explain to me what is char, varchar, nvarchar, and nchar.

6 Upvotes

I seriously don't understand it.


r/SQL • • 4d ago

Discussion What are some interesting SQL problems or query mistakes worth discussing?

0 Upvotes

I'm planning to share some SQL-related content on LinkedIn, but I want to avoid the usual beginner-level tutorials or generic interview questions.

I'm particularly interested in intermediate-level SQL concepts, window functions, CTEs, tricky query behavior, or situations where a query looks correct but produces unexpected results.

I'd love to hear from people working with SQL regularly.

What's an interesting SQL problem, subtle query mistake, or unexpected behavior you've encountered that made you think twice?

Looking for something technically meaningful that could spark a good discussion rather than another basic SQL tutorial.


r/SQL • • Dec 07 '22

MySQL Where can I learn SQL? Spoiler

0 Upvotes

I want to learn python and SQL, where is the best place for this?


r/SQL • • Aug 22 '23

Discussion What's that one interview question you like to ask that often knocks out candidates?

6 Upvotes

The reason I ask is I have a set of advanced questions with execution plans and common performance issues. But sometimes, it's the simpler questions that candidates miss. Here's one that often trips them up.

Write a query on this reservation table to count how many rooms are reserved right now. The table has ReservationID, CustomerID, RoomID, ReservarionStartDate and ReservationEndDate. The date columns are both DATETIME NOT NULL.


r/SQL • • Jul 08 '25

MySQL Got rejected after a perfect SQL assessment at Google - seeking insight

41 Upvotes

Hi all,
I recently applied for a Business/Data Analyst role at Google and went through their SQL assessment stage. It was a timed, 30-minute, non-proctored test with covering SQL joins, windowing logic, unique user counts, temporal queries, and a favorite JOIN question.

I worked hard to prep, answered everything accurately, and tied some of my responses to real-world work experience. I double-checked my answers after the fact, and everything seemed correct, logical, and clear.

I just heard back with a rejection: "Based on the results of the SQL assessment, they have decided not to move forward to the interview stages with your application at this time."

I’m confused and, honestly, a bit disheartened. The assessment wasn’t proctored, and I know how subjective some grading can be—but I genuinely believed I did well. I’d love to hear

  • Has this happened to anyone else with Google or other big tech companies?

  • Could timing, formatting, or SQL dialect (e.g., MySQL vs BigQuery) be a factor?

  • Is it common to get rejected despite a perfect technical solution?

  • Any tips for standing out better next time?

I’m still very interested in Google and plan to keep applying, but would appreciate any guidance, reassurance, or even a reality check from folks who’ve been through this.

Thanks for reading.


r/SQL • • Nov 24 '25

Discussion Learning SQL, should I Invest in a PC, or proceed with Mac?

0 Upvotes

I’ve searched and found a lot of info of different databases and management tools that work with Mac. I’ve done some learning in the past on a Mac before taking a different career path.

My question though, is should I plunge into learning on a Mac? How likely am I to run into or use Macs in an actual job? Are there nuances between Mac and PC that will make being successful in the job force more difficult? Or is it more a situation of just dive in and start learning and transferring isn’t a pain? Or would I be positioning myself for success to invest in a PC?

I just don’t want to start down this path only to find out I’ve done myself a disservice by not beginning on the correct platform.

Thanks for your input.


r/SQL • • Oct 17 '25

MySQL I built a MySQL Query Pack with 100+ ready-to-use SQL templates — feedback welcome

0 Upvotes

After years of working with SQL, I realized I was rewriting the same CRUD and reporting queries over and over.

So I packaged my most used MySQL queries into a reusable pack for developers.

It covers:

• CRUD operations for common tables

• JOIN patterns (INNER / LEFT / EXISTS)

• Reporting & analytics (cohorts, funnels, KPIs)

• E-commerce queries (orders, customers, revenue)

• Data quality snippets

I'm not here to hard sell anything — just want honest feedback from other SQL folks.

If anyone wants the link, I’ll drop it in the comments.


r/SQL • • Mar 14 '23

MySQL Can anyone tell me what this query and sub query trying to calculate

Post image
1 Upvotes

r/SQL • • Jun 12 '26

PostgreSQL Can where saves my files .sql?

0 Upvotes

Morning guys.

I was looking to save my .sql files somewhere with a focus on versioning, organization, and easy access. I use DBeaver, but I wanted something more "professional." The only idea that comes to mind is Git. I know DBt and I've already asked Claude/gpt, but the only idea he suggests is Git.


r/SQL • • 16d ago

Discussion the ghost in my halloween sql case is a NULL, and submit checks three logs you cant see

Post image
0 Upvotes

the case: an archive locks at ten, books still go out at 3am, and staff_id is NULL on every one. WHERE staff_id = NULL returns zero rows and no error, so written that way the archive looks empty. IS NULL finds them

the grading was the fiddly part. you can see the sample rows, so its easy to write a query that fits them and not the question. submit compares your rows with a reference query's on the sample and on three more logs you dont see. one hidden log has a signed checkout at exactly 22:00:00 and one at exactly 08:00:00, which catches > for >= and <= for < in the first query. the hidden logs also have an unstamped checkout in the daytime, so a second query that drops the time window fails. it only catches the mistakes i thought of, it doesnt prove a query right

free, runs on duckdb in the tab. after the case there are three harder ones: a recursive cte that has to stop on a cycle, gaps and islands, and an anti-join with a window

some of you answered my questions here in august, thank you for that.

https://tsunderesql.com/halloween/?utm_source=reddit&utm_medium=sql&utm_campaign=halloween1031


r/SQL • • Dec 02 '23

Discussion Learning SQL basic at 27 years, Am I too late to learn it?

0 Upvotes

Recently I stumbled upon power bi, and joined in a 5 months long data science basic course! There I had one SQL lecture and it felt like I can atleast learn the basics.

I am final semester masters student who wants to pursue career on supply chain and logistics. I have 2 years experience logistics.

Need some serious encouragement!

Edit - I know everyone is bit pissed about my post. I was recently thinking about doing my 2nd masters on business Analytics. I am an South asian guy who is doing masters in Germany on international management and sustainability which I have no interest on. But the degree is free so jumped into it. I wasted two years in this degree and finally felt that I need to learn some skills. I learn basic excel last year which help me to boost into other things.

Today while working in restaurant with my friend, I shared my desire on 2nd masters and he said like why am I keep having student status and becoming old and not getting proper job! I had my first weed experience today at work and I was high (damn weed is amazing, my manager gave me the weed shot). Then suddenly I felt like I am getting too old and not ready to get into jobs! I felt down and post this thing. I bought a sql course this month which is in my native language and the instructor is good (he is also taking my data science classes). I know the journey is long but I am getting influenced easily by other's negative comments and get demotivated.


r/SQL • • Mar 16 '23

MySQL As soon as I add the AVG(ProductStandardPrice) line I get errors. but if I delete that part it runs fine. Why is this and how do I fix this so I can make it show a list of average prices as well?

Post image
0 Upvotes

r/SQL • • Nov 25 '25

Discussion SSMS 22 - Copilot 'Format my Stored proc'

0 Upvotes

“SSMS 22 + Copilot: ‘Can you format this?’ → loses all metadata and adds ‘Created by GitHub Copilot’ banner”

I asked Copilot "can you format this document?" After some time and some spinning cloud icons, I receive the formatted document.

a) All my carefully crafted 'Information' like: Author, Create date etc.. was 'removed
b) The formatted SP was 'similar' to the original

c) I got some NEW info: Note the lack of date.
-- Created by GitHub Copilot in SSMS - review carefully before executing
/*This procedure builds a command line to run an external Shopify API XX harvest executable, executes it via xp_cmdshell, captures the output into dbo.DataFromAPI_XX and returns tracing and error information when requested.*/

Using a different tool:
/*-- Created by SODA + AI

=== AI ANALYSIS RESPONSE ===

Analysis Type: Summary

Completed: 2025-11-25 12:00:02

### Category: Overall Purpose

This stored procedure, named `API_QL_QUERY`, acts as a wrapper to "harvest" data from an external API (specifically, Shopify's API) by executing an external executable via the SQL Server command shell.

It constructs a command with provided parameters, runs the executable to query and retrieve data, and stores the results in a database table (`dbo.DataFromAPI_XX`).

It supports tracing for debugging and handles errors, with a focus on transactional data retrieval for orders or similar entities. */

On one hand, I am a firm believer that AI will be a critical tool to support our development efforts, on the other hand, I am questioning dropping that Copilot windows without better provisioning for 'prompt review'.

When asked for can you format this document? a proper 'response' could have been: Please select these outputs 1)... 2)... etc. where each selection would provide for different outcomes.

Just a thought.
What do you think?


r/SQL • • Aug 26 '25

SQLite Do we even need the cloud anymore? Yjs + SQLite + DuckDB might be enough

0 Upvotes

So I’ve been playing around with Yjs (CRDTs for real-time collaboration) together with SQLite (for local app data) and DuckDB (for analytics).

And honestly… I’m starting to think this combo could replace a ton of cloud-only architectures.

Here’s why:

Collaboration without servers → Yjs handles real-time editing + syncing. No central source of truth needed.

Offline-first by default → your app keeps working even when the connection dies.

SQLite for ops data → battle-tested, lightweight, runs everywhere.

DuckDB for analytics → columnar engine, warehouse-level queries, runs locally.

Cloud becomes optional → maybe just for discovery, backups, or coordination—not every single keystroke.

Imagine Notion, Airtable, or Figma that never breaks offline, syncs automatically when you reconnect, and runs analytics on your laptop instead of a remote warehouse.

This stack feels like a genuine threat to cloud-only. Cheaper, faster, more resilient, and way nicer to build with.

Curious what you all think:

Would you build on a stack like Yjs + SQLite + DuckDB?

Or is cloud-only still the inevitable winner?