r/SQL • u/Gokul_00 • 5h ago
r/SQL • u/SlightlyBeigeWall • 7h ago
MySQL Completed SQL foundation from SQL Bolt, Now practicing on Hackrrank What to do next for learning more concept.
Also confused which sql language to choose, thinking of choosing T-sql of microsoft
r/SQL • u/querylabio • 11h ago
BigQuery BigQuery lessons
There are plenty of good free courses for general SQL, on Postgres, MySQL, SQLite and so on. But I couldn't find one dedicated to BigQuery that works without a BigQuery account. Most of them start with creating a Google Cloud project, or with the sandbox.
We build a BigQuery IDE, Querylab.io, and it turned out it already had what that needs:
- Its own SQL engine that runs in your browser. That's why they're free, and you don't need to sign up or install anything.
- Completions and error checks as you type, so you see a typo before you run the query.
- Every query shows what it would cost on BigQuery. You can ignore it at first, but on a real database a careless query costs money, and it's good to learn that early.
So we built 76 short lessons on top of it. Each one explains one idea with an example, then gives you a few challenges, and the site checks your answer. Some ask you to fix a broken query or to guess the result before you run it.
Most of the practice data is a sample of real UK MOT data. MOT is the yearly inspection every car in the UK over three years old has to pass, and the data is how each car did. Cool dataset btw. There's also a made-up online shop and some website analytics events.
The SQL is BigQuery's. For the basics it's very close to what you'd write anywhere else. There are three levels:
- SQL from zero: SELECT, GROUP BY, joins, dates, CTEs, window functions (35 lessons)
- What BigQuery does its own way: cost, partitions, arrays and structs, pipe syntax, scripting (29 lessons)
- Analytics on Google Analytics 4 data: sessions, funnels, retention (9 lessons)
It works best on a computer.
https://learn.querylab.io/lesson/select-where/
If a lesson confuses you, tell me which one and where you got stuck. I'd love any feedback, and we'll fix it.
r/SQL • u/dHEEPAk28 • 17h ago
PostgreSQL Do We Need SQL For Marketing Analytics Role
SaaS And Performance marketing guy with 6 Years Of Experience The next Role im targeting is fully into measuring like analyzing data , measuring and tracking [Marketing analytics ] for that Learning SQl Will Help Or Not , If Not Means What are all the skill set should i focus on now on learning , Drop Your Thoughts below , your inputs helps me to take decision
r/SQL • u/Syftkogtech • 10h ago
SQLite Where Boundaries Break: The Metric With Two Definitions
Start with the metric that has two plausible definitions, because that's where the boundary actually gets tested. Average order value is a good one: revenue divided by orders, or revenue divided by distinct customers, and does the numerator net out refunds or not. Both are defensible. Neither is "the" answer until someone writes it down.
That's the real dividing line. Not who can type a join, but whether the number has one owner and one definition that both the SQL and the English resolve to.
The setup I'd argue for has three tiers, and each tier only holds up if the one below it is in place. Postgres syntax below, but the shape is the same anywhere.
**Tier 1: plain-English answers for the business.** Safe only if the language layer reads from a metric store, not from raw schema. A definitions table is enough to start:
```sql
create table metrics.definitions (
metric_name varchar,
owner varchar,
sql_body varchar,
grain varchar,
updated_at timestamp
);
insert into metrics.definitions values (
'average_order_value',
'finance',
'sum(net_revenue) / count(distinct order_id)',
'order',
current_timestamp
);
```
If a question can't be answered from a row in that table, the honest reply is "we don't have that metric yet," not a confident guess. That one rule kills most of the drift.
**Tier 2: read-only SQL for analysts.** They need the grain and the filters documented, not just the tables. Column names lie. `status` on an orders table might mean fulfilment state or payment state, and whoever writes the query has to know which. Write it down once instead of re-explaining it in every thread.
**Tier 3: engineers on base tables.** Full access, because they maintain the definitions and rebuild them when the source schema moves. Tiers 2 and 3 cost real time to run, but that's the cost of keeping tier 1 honest.
Where it falls apart, in my opinion, is skipping straight from "we have tables" to "we have a chat box." Natural language over raw schema doesn't fail loudly. It answers confidently using a join you never intended, and the person asking has no way to tell.
So, for anyone here running a semantic or metric layer: who owns the definitions, the data team, finance, or the business unit? And has that ownership held, or does the metric drift back to whoever asks loudest?
r/SQL • u/BillOaks • 9h ago
Discussion During a turnover, you take over all SQL within the organization, business rules are missing, how do you attempt to run all SQL. Is data lost ?
The proposed quantitative experimental study will examine whether providing healthcare data analysts with documented business rules and analytical rationale improves the accuracy of healthcare reports when they assume responsibility for another analyst’s work. Harrold (2026) recommended controlled user experiments to evaluate analytical errors, recovery, rework, and continuity of healthcare analytics. The proposed quantitative experimental study will address one component of this recommendation by comparing the accuracy of analysts receiving standard documentation with those receiving enhanced documentation. The intended contribution is to provide healthcare administrators with empirical evidence concerning documentation practices that may improve the accuracy of healthcare reporting.
r/SQL • u/Glad-Raccoon-7224 • 1d ago
MySQL SteelSQL — a database client that works like a spreadsheet
I've spent six years building a desktop database client.
It's aimed at the part of DBeaver / DataGrip / Navicat people actually use every day — look at data, edit it, filter it, run a query — plus a modern interface and a good UX.
Performance — measured on one machine (M1 Pro / 16GB / macOS); method and numbers
- ~1s startup
- 1,000,000 rows × 100 columns: ~11.7s
- ~230MB idle, ~610MB peak under heavy operations
Tech
- Electron shell, with the UI layer built in-house: tree, tree-grid, data grid, SQL parsing, schema-aware completion
- Under 5% of the code is AI-generated; the rest is written and reviewed by hand
- Built-in AI: chat, inline chat, fix, explain, optimize (no model included — bring your own API key)
- ~120MB installer, database drivers bundled — nothing extra to download
Links
- Supported databases: https://steelsql.com/docs/overview/#supported-databases
- website: https://steelsql.com
- Free trial (2 tabs, 1 window): https://steelsql.com/download, One-time license, no subscription
I'm the developer; it's a commercial product. Happy to answer anything.
r/SQL • u/Altruistic_Source98 • 1d ago
Discussion Help Ric (Fabric) and Bob (SQL) try to survive a week of data deadlines
We built a little game for fun: **Data Desk Dash**.
**Play it here:** https://fabriccon.com/data-desk-dash.html
You play as Ric, our Fabric mascot, and Bob, our SQL mascot, keeping a busy data office running for a full work week. Every desk is a quick mini-game:
- Drag SELECT, FROM and WHERE into the right order
- Rotate pipe pieces to get a pipeline flowing into OneLake
- Pick the best chart for a Power BI report
- Time your tap to rebuild an index
- Pick the last good backup before the data was lost
Along the way you'll run into deadlocks, NULL spills on the floor, an empty coffee pot, and someone running DELETE without a WHERE clause. There's also a Fabric Data Agent power-up, and a pizza delivery guy who shows up when you need him most.
It runs in your browser on desktop or phone, with no sign-up. There's a 2-player mode too, if you want to team up with a coworker on one keyboard.
When your run ends, win or lose, you'll get a code for **$100 off a Diamond, Platinum or Gold Pass** to FABCON SQLCON 2027 in Atlanta, March 8–12. Register at https://fabriccon.com/tickets
Post your best score!
r/SQL • u/Appropriate-Run-7005 • 1d ago
SQL Server Running 1,000 Standalone SQLite Databases Inside SQL Server
I couldn't add both databases to the required Tag, so I hope this is ok. Enjoy
r/SQL • u/Think_Percentage_959 • 1d ago
DB2 Need help on DB2 design
reddit.comProblem Statement
We have a transaction history table (CARDTXNHIST) used by a banking application to display customer transactions.
The daily batch process consists of two stages:
Unstatemented Transactions (Code = 2)
batch file → TEMP table → View → CARDTXNHIST
Existing Code=2 records are deleted and refreshed
Statemented Transactions (Code = 3)
Separate batch file → TEMP table → View → CARDTXNHIST
Statemented records are loaded after unstatemented processing
The batch window runs approximately between 4 AM and 9 AM.
Observed Issue
On statement cycle dates, the incoming unstatemented dataset may be empty because all eligible transactions have been statemented.
As a result:
Code=2 transactions are removed/refreshed
Code=3 transactions are still being processed
During this period, customers may see no transaction history in the application, even though the transactions still exist within the batch pipeline.
Objective
We are looking for database/application architecture approaches that can eliminate or minimize this visibility gap while the batch is in progress.
Solutions Under Consideration
Retaining Code=2 records until Code=3 processing completes
Shadow table / table-swap approach
Composite views
Deferred commit strategy
Reading from staging/view sources during batch processing
Data archival and performance optimization
Other database design recommendations
Questions
What would be the recommended design pattern to ensure customers always see a consistent transaction history?
How have similar large-scale batch processing systems solved this "delete-before-republish" visibility gap?
Are there DB2-specific approaches (isolation levels, shadow tables, transition tables, view-switching, etc.) that would be suitable for this scenario?
If you'd like to adjust the length or add any extra context (like table volume or specific DB2 version) before posting, let me know!
r/SQL • u/DesignerDetective518 • 2d ago
MariaDB myflames update: VillageSQL support, Galera Cluster bootstrapping, and Readyset improvements
r/SQL • u/DataFracking • 2d ago
SQL Server Open Source Extension for SSMS 22 -> Tab Result History
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/winstr12 • 2d ago
MySQL [MySQL] I'm doing a personal project and need help with importing a large amount of CSV files (+1000)
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 • 2d ago
Discussion Trying to build custom Data Orchestration and Federation engine from scratch
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!
PostgreSQL [DuckDB/PostgreSQL] I built a free practice site for intermediate & interview SQL: window functions, CTEs, anti-joins, cohorts
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/MadeSimpleMSSQL • 2d ago
SQL Server SQL Server Interview Questions and Answers Part - 75
r/SQL • u/Sad_Zucchini285 • 3d ago
SQL Server Review of my school database requirements (university project)
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)?
r/SQL • u/Temporary_Papaya1058 • 3d ago
PostgreSQL BIRD verified my text-to-SQL entry on LiveSQLBench-Large, and reproduced a 40.21% agent run
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/Then-Macaroon9958 • 5d ago
Discussion How to progress with SQL?
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/MrRoy_SQL • 5d ago
Discussion LAST_VALUE kept giving me the current row instead of the last one. the default window frame was the reason
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?
PostgreSQL Connection pooling & read/write isolation with Lakebase
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/Fun_Disaster_5965 • 5d ago
MySQL MySQL InnoDB – Index Gap Deadlock with Concurrent INSERT … SELECT
reddit.comr/SQL • u/tombarrett82 • 5d ago
SQL Server SSMS 22 extension skill
Reposting to this group in case others are interested, thanks
r/SQL • u/FunAd6672 • 5d ago
PostgreSQL Moving into a data analyst role next year and figuring out how much SQL to learn past joins and GROUP BY
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?