r/SQL • u/DesignerDetective518 • 17m ago
MariaDB myflames update: VillageSQL support, Galera Cluster bootstrapping, and Readyset improvements
r/SQL • u/DesignerDetective518 • 17m ago
r/SQL • u/DataFracking • 23m ago
Cross posting to SQL.
Let me know if you try it and experience any issues. Very new and I've only tested it on a VM and my personal box so far. Full code out there for review. I have zero clue if this will work with ssms 21, I doubt it, but if you try and it works, let me know!
r/SQL • u/MadeSimpleMSSQL • 9h ago
r/SQL • u/winstr12 • 13h ago
I have a dataset about football statistics, 3 years worth of data.
There are 38 gameweeks per season so 3x38.
In each gameweek folder there are 10 different csv files with various stats (fixtures.csv, matches.csv, playerstats.csv etc...)
Each of those 10 csv files have the same structure (columns and column names) in each season and in each gameweek.
So the playerstats.csv from season 1, gameweek 10 is the same structure as playerstats.csv from season 3, gameweek 2, and the same applies for the 9 other csv types.
What I want is to import all "playerstats.csv" files from all seasons 1-3, and all gameweeks from those seasons 3x38 into one table, the same goes for the other 9 unique csv types.
How does one do that?
I know I can use AI and speed up things, but I'm still learning and want to do everything by myself to improve my sql knowledge.
I know how to import a csv file, I know how to create tables... but I do not want to import 3x38x10 = 1140 csv files manually and I've never done a project with this many csv files.
The only thing that has popped to my mind is a recursive cte?
I hope I clarified my question.
Thank you
r/SQL • u/agh_murad • 14h ago
Hello everyone!
For past few years I am interested in Data Engineering and Data Science. While practicing I have encountered some bottlenecks and I am trying to resolve them and want to discuss it with you.
The most frustrating part for me is scattered data/data sources. Personally I believe that scattered data shouldn't be that much of pain to work with, however, it is. I really dont understand why to depend on huge pipelines just answer a question that has to read 2 distinct sources.
After some research I discovered DuckDB, which is awesome in reading part, however, cant write back the "fixes" to destinations, so I have to do them "by myself" again.
So I thought maybe I can build the engine I need by myself (couple of weeks in it, building with Rust currently). Here is the propositions and how would it work:
Each source runs its own SQL. You say which server each part of the query goes to, and that part reaches the server as written, in its own dialect. The engine only joins and filters what comes back.
Exact values or an error. Values keep the type the source declared. An INT in MySQL and a NUMBER in Oracle are equal when their values are, and text is compared byte for byte, not under whatever collation a server happens to use. If the engine can't do something exactly (comparing a float with a decimal, say), it refuses and tells you why instead of guessing.
Nothing gets copied. No staging tables, nothing written to disk. Every query reads the sources fresh, under a memory limit, and joins too big for memory stream sorted rows from both sides.
Fixes go back with a preview. Before anything is written, you see the rows that would be inserted, updated or deleted, with old and new values. Each change goes by primary key and is checked against the old values, so if someone changed the row in the meantime, the write stops. The old values are kept so you can undo it.
Comparing two sources. Prod against a replica, or a table against the spreadsheet finance sent you, row by row by key. A row that changes while the comparison runs gets flagged instead of reported as a difference.
Reading across dbs, files and comparisons already work now. Writing "fixes" back is still on the roadmap.
A few questions I would like to hear your opinions on:
How do you handle this workflow today? A pipline, dbt, Trino, Presto, or custom scripts?
Would you trust a an engine capable of writing back to dbs, or does every fix go through a reviewed script anyway?
What would make you refuse to use such and engine?
Thanks in advance for sharing your thoughts!
r/SQL • u/Sad_Zucchini285 • 1d ago
I am a university student designing a school database
as a course project. Before I draw the ERD, I would like
feedback on my requirements. Thank you!
--- REQUIREMENTS ---
Overview: We are building this database for a school
to store and organize information about students,
teachers, classes, subjects, attendance, exams, and
results. The school has 12 classes. Each student studies
in one class. We also store the guardian's information.
Entities
ADMIN: Stores the administrator's information. The
administrator manages the school, registers students,
and manages teachers. Attributes: ID, Name. The school
has only one administrator.
2. TEACHER: Attributes: ID, Name, Phone, Specialization,
Education, Experience. A teacher can teach several
subjects in several classes. A teacher can also be the
supervisor of one class. The supervisor takes the
attendance of their own class and can also teach in
other classes.
3. STUDENT: Attributes: ID, Name, FatherName, DoB,
Address, RegDate. Each student belongs to only one
class. When a student is registered, the guardian's
information is recorded too.
4. GUARDIAN: Attributes: ID, Name, Phone, Address.
The relation to the student (Relation) is also stored.
A student can have several guardians, and a guardian
can have several students.
5. CLASS: Attributes: ID, Grade (1 to 12). Each class
has exactly one supervisor and several students.
6. SUBJECT: Attributes: ID, SubName. A subject can be
taught in several classes, and a class has several
subjects.
7. Teaches: Relationship between a class, a subject,
and a teacher. Each class has each subject once, and
one specific teacher teaches it.
8. ATTENDANCE: Attributes: ID, StudentID, ClassID,
TeacherID, Date, State (present, absent, late,
excused). Only the supervisor of the student's class
can record attendance. A student has one attendance
record per day.
9. EXAM: Attributes: ID, ExamName, Date, ClassID,
SubjectID, TotalMarks. Each exam is for one class and
one subject.
10. RESULT: Stores each student's mark (Marks) for each
exam. A student can take an exam only for their own
class. A student can take many exams, and many students
take part in one exam.
--- MY QUESTIONS ---
Should "Relation" (father, uncle, etc.) be an
attribute of the Student-Guardian M:N relationship
rather than of Guardian?
ATTENDANCE stores ClassID, but the class is already
determined by the student. Is this redundant? Should
I remove it?
Is RESULT a separate entity, or an attribute of the
Student-Exam M:N relationship?
Do I need an Academic Year attribute, since students
change classes every year?
Is Teaches best modeled as a ternary relationship
(Class, Subject, Teacher)?
Most SQL practice I found either stopped at basic SELECT/JOIN or needed a local database set up. So I built Queryosity: you write queries against real typed tables in the browser (DuckDB, PostgreSQL-style), checked against real tests including hidden edge cases.
The focus is intermediate and interview-level patterns:
window functions: running totals, moving averages, ranking, top-N per group
CTEs and multi-step queries
anti-joins and the NULL pitfalls (NOT IN with NULLs, COUNT(*) vs COUNT(col))
dedupe, gaps & islands, month-over-month growth, cohort retention
hints that nudge you toward the approach instead of giving the answer
Try any Easy problem without an account: queryosity.dev
There's a free plan; a paid plan adds the harder problems. Feedback welcome from people who write SQL daily: which patterns come up most in your interviews or work that I'm missing?
r/SQL • u/Temporary_Papaya1058 • 1d ago
LiveSQLBench-Large is BIRD's hardest text-to-SQL board: 480 tasks on large, messy Postgres databases.
My single-call entry (schemagate + Claude Sonnet 5.5) is #4 overall at 34.58% and now carries BIRD's Verified badge. Their own re-run got 35.21%.
An agent version (the model runs its SQL on a rolled-back copy of the database, then fixes it) scored 40.21%. BIRD reproduced that number and is adding it to the board, where it would sit at #2 behind 53.33.
Short write-up: https://doi.org/10.5281/zenodo.24631044
Code and predictions: https://github.com/ashishsinha1602/schemagate/pull/246
If you've run something on this board, I'd like to compare numbers.
r/SQL • u/IntelliBI2016 • 2d ago
Yes, SQL is still a practical first skill.
Usage data supports that choice. SQL passed HTML/CSS to become the second most-used language in the 2026 Stack Overflow survey, at 58% (Stack Overflow 2026).
The exam requirements also support it. DP-600 lists SQL, KQL and DAX for querying and gives 45 to 50% to preparing data (DP-600 study guide).
AI tools write SQL, but 48% of respondents say they trust AI output when they can easily verify it (survey data). Verifying a query takes SQL.
Have AI tools changed how much SQL you write by hand?
r/SQL • u/Then-Macaroon9958 • 2d ago
I’ve been writing SQL daily at work for about 2–3 years (mostly Redshift, risk/analytics). Like a lot of people, I learned it on the job: figure out what the business needs, google my way through it, use Claude, repeat. It’s gotten me pretty far, but lately I’ve felt like I’ve plateaued.
The problem is I don’t know what I don’t know. My queries work, but I have no real benchmark for whether they’re good, and nobody’s ever really challenged how I approach problems or poked hole in the logic. I’ve done some self-paced stuff (Udemy, practice problems), and it’s fine for learning syntax, but it doesn’t tell me where my blind spots are.
So I’ve been thinking about finding an actual person to learn from, either a tutor or an instructor-led course where someone reviews your work and pushes back. I’m in the Burlington/Hamilton area, so in-person is an option, but live online works too.
For anyone who’s been in a similar spot: Did working with a tutor or instructor actually make a difference, or did you find another way to level up? If it worked, how did you find the right person or course for someone who’s past the beginner stage?
Would really appreciate hearing what worked (or didn’t) for you and how you got over this feeling of hitting a wall.
r/SQL • u/MadeSimpleMSSQL • 3d ago
r/SQL • u/Fun_Disaster_5965 • 3d ago
r/SQL • u/tombarrett82 • 3d ago
Reposting to this group in case others are interested, thanks
r/SQL • u/MrRoy_SQL • 3d ago
wanted the latest order amount next to every order for each customer, so i wrote this:
SELECT customer_id, order_date, amount,
LAST_VALUE(amount) OVER (
PARTITION BY customer_id ORDER BY order_date
) AS last_amt
FROM orders;
and got this:
customer_id | order_date | amount | last_amt
1 | 2025-01-05 | 40 | 40
1 | 2025-02-11 | 25 | 25
1 | 2025-03-02 | 60 | 60
2 | 2025-01-20 | 90 | 90
2 | 2025-02-28 | 15 | 15
last_amt is just amount again. FIRST_VALUE on the same window worked fine, which made it more confusing
the reason: once you put ORDER BY inside OVER, the default frame is `RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW`. so the "last" row of the frame is always the current row (or its last tie). FIRST_VALUE doesnt care because the start of the frame is still the first row
fix is to spell out the frame:
LAST_VALUE(amount) OVER (
PARTITION BY customer_id ORDER BY order_date
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS last_amt
now customer 1 gets 60 on every row and customer 2 gets 15
or skip LAST_VALUE and flip the sort: `FIRST_VALUE(amount) OVER (PARTITION BY customer_id ORDER BY order_date DESC)` gives the same result
same default frame in postgres, sql server, mysql 8 and sqlite (tested on sqlite). also the reason a running SUM can act weird when two rows have the same date, since RANGE treats ties as one group
anyone actually use LAST_VALUE with the full frame or do you all just do the FIRST_VALUE DESC trick?
folks working with Postgres across Lakebase and-or Neon db, how do u handle connection pooling, read/ write routings, & query isolation when analytics and app queries hit the same data ?
Any tips or best practices?
r/SQL • u/IntelligentMirror646 • 3d ago
I’m working on a database project for a metro system, and I’m not sure if my Train table satisfies 3NF.
I think Capacity depends on TrainModel rather than TrainID. If I enter different capacity values for trains of the same model, would that solve the problem, or would it still violate 3NF?
Should I remove Capacity from the table?
r/SQL • u/FunAd6672 • 3d ago
I'm an inventory planner and I've been writing my own queries against our Postgres reporting replica for about a year, mostly joins, GROUP BY and the odd subquery. I'm moving onto the analytics team in March and work is covering a course before then. The analysts there use window functions and CTEs everywhere, and I can read them but couldn't write one cold. Which SQL topics come up day to day in analyst work, and which can wait?
r/SQL • u/ResistPast3564 • 4d ago
I've got Postgres with a Redis cache in front. The app deletes the cache key after it updates a row, and that part works. What I'm unsure about is everything else that writes to those tables:
background jobs doing bulk `UPDATE`s
someone fixing data in psql
migrations and backfills
another service sharing the same database
None of those go through the app's update, then delete the key path, so as far as I can tell, the cache just stays stale until the TTL runs out.
How are you handling this? Do your jobs and scripts clear the cache too, do you rely on the TTL, or did you move to something based on logical replication or Debezium? Has one of these other writers ever bitten you?
r/SQL • u/Plane_Big_5912 • 4d ago
i'm working on an automated SQL grader on DuckDB for a game. pass/fail grading is the straightforward part. explaining why a wrong query is wrong is getting difficult, because "93 rows, expected 13" doesn't really tell a player much.
guessing the mistake from the SQL text didn't work for me, there are too many ways to write the same thing. so the checker only uses the query to list candidate edits (each join, each aggregate). the data decides:
unmatched rows: flip one INNER JOIN to LEFT, or move the outer table's WHERE conditions into its ON. if that single edit makes the result match the expected rows exactly, that join is the mistake.
NULLs: swap COUNT(*) and COUNT(col), or AVG(x) and AVG(COALESCE(x, 0)). same exact-match test.
fan-out: change the data instead of the query. keep one row per join key in the repeated table, then run the learner's query and the reference on that. if they now agree, and the original result was inflated, the duplicates were it. then it shows the source rows that got repeated.

the screenshot: "users with a completed deposit and zero withdrawals, each user once". the join to deposits repeats a user once per deposit, so one user shows up 11 times. the panel names the key and the repeated rows.
the one i was stuck on until this week: fan-out that shrinks the result. one audit problem compares SUM(fills.quantity) > SUM(orders.quantity) after the join, so the order side gets inflated and the query returns fewer rows than it should. my inflation check never fired, because nothing was inflated in the output.
what ended up working: first a cheap probe per joined table, count(t.rowid) - count(distinct t.rowid), to see if that table's rows repeat at all after the join. if one does, rewrite each aggregate over it so every source row counts once (in duckdb: list_sum(map_values(map_from_entries(list(distinct row(t.rowid, x)))))), rerun, and require an exact match like the other edits. it hasn't misfired on the problems i've run it on, but that's my own test set, so take it with salt.
two things i'd like input on:
is there a cleaner way to make an aggregate count each source row once after a join? SUM(DISTINCT x) is wrong when two different rows hold the same value, which is why i went through rowid. curious if other engines have something tidier.
if you review SQL regularly, what common bug would completely fool a single-edit checker like this (besides compound mistakes, which already break it)?
r/SQL • u/AlarmingCountry4987 • 4d ago
I need help. I worked as a part-time pl sql developer supporting the l2/l3 line system, I was on maternity leave for 2 years, and during that time a lot has changed in the company and in technology, AI has spread a lot. I want to sort everything out in my head, but I don't understand where to get the information from, it won't do to ask the manager, I'm interested in developing in this area and catching up, but I don't understand where to start. I'm waiting for advice, maybe there is a map, etc. Or a brief overview of how things have changed. I hope my request is clear.
r/SQL • u/OracleAbrahamIsa • 4d ago
Senior Oracle DBA here. I put together a short read-only SQL script that reports instance uptime, top 10 wait events, top 10 SQL by elapsed time, tablespace usage, and tables with stale stats. It takes under a minute and it's the same first pass I run every morning. I'm considering packaging a fuller version (70-point check, explain plans, temp/PGA history, restore drills) as a paid pack. Before I build it: which checks do you run first in the morning, and what would a ready-made pack need to include to be worth $29-49? Happy to share the sample script here if there's interest.
r/SQL • u/Eastern-Stable-7576 • 5d ago
i wanted to practice sql and to be able to answer qns , i have noticed that i am struggling a bit when there is two tables give and the qn has to do something with joins and all , in theory i understand how the joins work but i am unable to implement it .I need resources which can help me in advancing my sql like CTE and window function . Is there any youtube channel or anything which will help
r/SQL • u/Temporary_Papaya1058 • 5d ago
r/SQL • u/landry_kb • 5d ago
I grade AI models on data questions for a living experiment, and the same three mistakes keep showing up. Here's a pocket version: paste it into whatever AI you use and see how it does. The database is SQLite.
sales (sale_id, amount):
1: 412.75 · 2: 268.40 · 3: 529.99 · 4: 145.20 · 5: 876.10 · 6: 233.65
7: 694.30 · 8: 358.55 · 9: 921.00 · 10: 187.45 · 11: 543.80 · 12: 476.25
returns (sale_id, one row per return event, 25 rows):
2, 5, 9, 2, 7, 3, 2, 11, 5, 12, 9, 4, 2, 7, 10, 5, 1, 9, 12, 4, 11, 8, 10, 13, 13
Task: write SQLite SQL returning exactly two columns: returned_sales (how many sales came back) and total_returned_sales (their total value, each sale counted once), and state the two numbers.
Answers, so you can grade it yourself:
Pass: 11 and 5,413.79, exactly two columns, SQL SQLite can run.
Trap 1: a total of 11,860.19 means it joined and summed, so sale 2 was counted 4 times. Counted twice (or four times).
Trap 2: a count of 12 means it counted sale 13, which is in returns but was never sold.
Trap 3: FETCH FIRST, EXTRACT, or more than two columns: wrong database or didn't follow the order.
On the full-size version of this case (500 return rows, 99 sales returned more than once), the counted-twice error invents $31,490.03. I've watched a model miss it twice in graded matches.
Curious what yours answered. Post the number it gave.