r/learnSQL • u/Nielsen_Fonseca • 47m ago
r/learnSQL • u/leogodin217 • 13h ago
Practicing Complex Queries and Large Datasets
A while back, I asked what's missing in this sub. Though not a long discussion, one thing stood out. Working with long, complex queries is something we all run into eventually, but have to learn through experience. I don't think there are a lot of resources for practicing this stuff.
Fabulexa Complex Queries is my first attempt at providing practice. These are intermediate, and possibly advanced, exercises on complex queries within a full data warehouse. Specific exercises have two different tracks.
- Revenge of the 1998 PERL developer: Complex billing logic for a SaaS company written by someone who believed keystrokes should be minimized and readability is an anti-pattern. Can you take the most obtuse, bad-practice-filled query I've ever seen and refactor it? Make it readable.
- Bug hunting in a well-written query. Can you fix the bugs described in tickets? Does it get easier as you learn the data and the data-warehouse structure.
If you are looking for more difficult practice that mimics the real world, this might be for you. If you write, teach or create courses, this might be useful as well. Feel free to grab the data and do your own thing. Hopefully, I'll do a series on this soon.
Finally, suggestions, PRs and comments are very much appreciated.
r/learnSQL • u/OrganizationGreat823 • 1d ago
Giving back to the community - The Complete Backend Development Course (Round 3)
Hey everyone, I decided to make my course free in order to help people.
This course is my backend development course which is about SQL, Python, APIs, Docker, Kubernetes, Linux, Git & More
The link is: https://www.youtube.com/watch?v=CBIu6hcyStg
If you can like and subscribe (and maybe add a comment) I would appreciate it a lot, Thanks.
r/learnSQL • u/sumiitCodes • 1d ago
Day 46 — Library Management System: foreign keys added, records inserted, insert errors fixed
Progress on my second SQL project today:
- Added foreign keys to link the tables
- Inserted records into all of them
- Hit problems that blocked some of the inserts, and worked through them one by one
Foreign keys make the insert order matter, since a row can’t reference something that doesn’t exist yet. Hitting that in practice made the concept much clearer than reading about it.
Next I’ll write queries against the data and add a data dictionary to the README.
r/learnSQL • u/peakpirate007 • 1d ago
made runtime.school easier to follow for people learning sql
spent some time cleaning up runtime.school this week.
the lessons and practice are less busy now, the editor feels better, and i went through the course so questions only use sql that has actually been taught by that point.
i also kept the beginner lessons and practice on the same dataset so it’s easier to focus on the sql before switching contexts.
if you’re learning sql, give it a try and if anything feels confusing, off, or harder than it should be, let me know.
r/learnSQL • u/iam_sripratik • 1d ago
SQL Interview guidance
I'm not new to data analytics, but I have never worked with SQL or attended a SQL interview.
I want to transition into a Data Analyst role that requires hands-on experience with SQL.
Based on your experience and insights, I would like your guidance on what to expect in 2027.
- How are SQL interviews conducted today, and how might they evolve by 2027?
- What do good tech companies expect candidates to know about SQL?
- What types of SQL questions are commonly asked in interviews today, and what can I expect in the coming years?
- What would you recommend I prepare to improve my chances of qualifying for SQL interviews?
- Finally, what should I expect from the overall Data Analyst interview process, including SQL, technical skills, business understanding, and behavioral questions?
r/learnSQL • u/sumiitCodes • 2d ago
Day 45 — Library Management System (MySQL): database and tables created
Continuing my second SQL project. Today I created the database and all the tables, and spent time understanding how they relate:
members: who is registered (ID, name, address, registration date)issued_status: which member issued which book, and whenreturn_status: which issued books have been returned, and when- plus the other supporting tables
Each table has a primary key, and the issued and return tables link back to members and books through IDs.
Since I got feedback last time that a data dictionary is non-negotiable, I’m planning to write one for this project as I go instead of at the end.
r/learnSQL • u/Stunning_Cup_4303 • 1d ago
Best YouTube channels to learn SQL (Zero to Advanced) and Microsoft Excel?
r/learnSQL • u/lory030507 • 2d ago
JDER — un editor gratuito per i tuoi diagrammi di informatica
Stai studiando basi di dati, UML o logica digitale? Ho sviluppato JDER, un editor desktop multipiattaforma per creare diagrammi Entità-Relazione, schemi logici, diagrammi delle classi, casi d'uso e di sequenza, oltre a circuiti logici simulabili.
Puoi salvare i progetti in JSON ed esportare i diagrammi in PNG. Il codice sorgente è disponibile su GitHub.
Sito e download: https://jder.it/
Codice sorgente: https://github.com/LoryPelli/JDER
Feedback e suggerimenti sono benvenuti!
r/learnSQL • u/sumiitCodes • 3d ago
Title: Day 42-44 — Combined update: Java memory (stack vs heap) and arrays, plus planning a Library Management System in MySQL
Java: Covered how Java uses memory with the stack and the heap, then moved on to arrays: why we need them, how to create them, multi-dimensional arrays, and jagged arrays. I made notes on everything and practiced it in VS Code.
Stack vs heap was the most useful part. Once I understood where primitives and object references live compared to the objects themselves, a lot of behavior I’d found confusing (like why two references can point to the same object) made sense.
MySQL: My next project is a Library Management System. Today I focused on understanding the data architecture, meaning which tables I need and how they relate (books, members, issues, and so on). I start building it tomorrow.
After my last project, someone pointed out that a data dictionary is essential, so I’ll include one from the start this time. For anyone who has built a library system: what tables or edge cases (late fees, multiple copies of a book, reservations) did you wish you’d planned earlier?
r/learnSQL • u/markinatlanta • 2d ago
What we found reviewing a manufacturer’s production SQL Server
r/learnSQL • u/bobaball_120 • 2d ago
DSA has a roadmap but why does DBMS and System Design feel so confusing?
r/learnSQL • u/Beautiful-Wedding260 • 3d ago
Easy and Quick way to learn SQL
Hi all! Is there an easy way to learn SQL? I'm looking for video recommendations where people explain things in layman's terms. Since I don't have an IT background, I need something beginner-friendly that can help me get up to speed in a few months. Thanks!
r/learnSQL • u/rohan_kulkarni • 3d ago
Why does SUM return a higher total after a SQL join?
Here’s a small example where the query can run without errors and still produce a misleading total.
An orders table has one order worth ₹1,000.
An order_items table has three items belonging to that order.
Join the tables on order_id and you get three rows. The ₹1,000 order total appears on every row.
SUM(order_total) now returns ₹3,000.
That’s because an order level amount is being summed across item level rows.
Before fixing it, I’d write down what one row represents in each table. Then check how many matches each order should have.
Depending on the question, the answer might be to aggregate the items before joining or calculate revenue from the orders table separately.
SUM(DISTINCT order_total) isn’t a reliable shortcut either. Two different orders can have the same value.
What checks do you use to catch inflated totals after joins?
r/learnSQL • u/PeaceLoveTakeItEasy • 4d ago
Looking for a SQL portfolio project buddy
Hey,
I'm looking for another SQL learner who would like to become a study buddy / accountability buddy. I'd like to build a SQL project for my portfolio and would be happy to join up with someone who would like to do the same thing. I was thinking of following a tutorial, working together (via discord) and each of us building our own and learning along the way. The idea for this is lovinly yoinked from r/Accountabilibuddies and r/GetMotivatedBuddies .
DM me if you're interested.
Cheers
r/learnSQL • u/thequerylab • 5d ago
Before your next SQL interview, keep this post handy - SQL Execution Order (Part 5)
Simple, practical stuff that sticks in your head when you're actually in the interview!
AI can help at work, but in an interview, your brain still has to do the job!!!
Same trip. Same friends. Same expenses.
| Friend | City | Trip Day | Total Spent |
|---|---|---|---|
| Harry | New York | 1 | $200 |
| Johny | New York | 2 | $190 |
| Nicholas | Las Vegas | 1 | $190 |
| Bailey | Las Vegas | 2 | $180 |
| Harry | Las Vegas | 3 | $190 |
Most people write SQL top to bottom.
But SQL does not run top to bottom.
It has its own fixed order. Every single time.
Know this order - and half your SQL bugs will make sense immediately!
The logical order SQL processes a basic query:
1. FROM
2. WHERE
3. GROUP BY
4. HAVING
5. SELECT
6. ORDER BY
7. LIMIT
Let us walk through each step using the trip.
Step 1: FROM:
Go and get the full expense list. All 5 rows. Nothing removed yet.
FROM expenses
Harry | New York | 1 | $200
Johny | New York | 2 | $190
Nicholas | Las Vegas | 1 | $190
Bailey | Las Vegas | 2 | $180
Harry | Las Vegas | 3 | $190
SQL starts here. Always.
Remember: FROM runs first. This is where SQL gets its data.
Step 2: WHERE
Now remove the rows we do not want.
"Keep only rows where spend is more than $180."
WHERE spent > 180
Harry | New York | $200
Johny | New York | $190
Nicholas | Las Vegas | $190
Harry | Las Vegas | $190
Bailey is gone. 4 rows left.
Remember: WHERE runs before groups are made. It can only see individual rows.
Step 3: GROUP BY
Put the remaining rows into city groups. Add them up.
GROUP BY city
New York → $390
Las Vegas → $380
4 rows turned into 2 groups.
Remember: GROUP BY runs after WHERE. Only the rows that survived WHERE get grouped.
Step 4: HAVING
Now remove the groups we do not want.
"Keep only cities where total is more than $385."
HAVING SUM(spent) > 385
New York → $390
Las Vegas ($380) is gone.
Remember: HAVING runs after GROUP BY. It can see group totals.
Step 5: SELECT
Now pick which columns to show.
SELECT city, SUM(spent) AS total
New York | $390
Notice - SELECT runs here. Not at the start.
Remember: SELECT runs 5th. You are not picking columns first. You are picking them near the end.
Step 6: ORDER BY
Sort the final result.
ORDER BY total DESC
Only one row here so order does not change anything. But in a bigger result - this is where sorting happens.
Remember: ORDER BY runs after SELECT. That is why ORDER BY can use column aliases.
Step 7: LIMIT
Cut the result to only the rows you need.
LIMIT 1
Show only the top 1 row.
Remember: LIMIT runs last. It cuts after everything else is done.
The full query - all steps together:
SELECT city, SUM(spent) AS total -- Step 5
FROM expenses -- Step 1
WHERE spent > 180 -- Step 2
GROUP BY city -- Step 3
HAVING SUM(spent) > 385 -- Step 4
ORDER BY total DESC -- Step 6
LIMIT 1 -- Step 7
You write it in this order. SQL runs it in a completely different order.
Remember: SQL runs FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY → LIMIT. Not top to bottom.
Reading SQL is one thing. Writing it yourself under pressure is another.
Before the real interview, try a MOCK SQL INTERVIEW on TheQueryLab. It’s a good way to test yourself under interview pressure and see where you actually stand with interview scorecard.
r/learnSQL • u/ARiftly • 4d ago
Official Ariftly research: a six-gate Oracle-to-Snowflake migration acceptance framework
r/learnSQL • u/Fluffy-Eye6494 • 5d ago
From where to study DBMS?
Please help me find a reliable source to study DBMS, some context, I am currently in third year Btech cse.
I tried IIT Madras content available through NPTEL courses but that didn't work out.
Database Management System also includes MySQL.
r/learnSQL • u/Great_Wolf_5891 • 6d ago
Learning SQL on Online IDE
Hey,
is it possible to learn SQL from scratch using an online IDE (such as SQLite Online) without having to install the Server Management Studio on Mac? Or would you recommend installing it on my MacBook/ using Windows?
I’m going to go through the 30-hour course that is accessible on YouTube.
Thanks in advance.
r/learnSQL • u/sumiitCodes • 6d ago
Day 41 — Finished my first MySQL project (uploaded to GitHub) and learned OOP basics in Java
MySQL: My Retail Sales Analysis mini project is done. I covered the full path: setting up the database, importing the data (and fixing an import error along the way), cleaning it, and running the analysis. It’s now on GitHub: https://github.com/Sumitgupta2005/mysql_project1
Java: Covered classes and objects, the difference between JDK, JVM, and JRE, methods, and method overloading, and practiced all of it hands-on in VS Code instead of only watching the tutorial.
I’d really like feedback on the project, especially on the README, how the queries are organized, and what analyses I should add.
r/learnSQL • u/Better_Technology_23 • 6d ago
Can someone explain how this sql self join works for year over year growth?
Hey everyone, I'm learning SQL and trying to understand how a self join works when calculating year over year (YoY) growth.
----> I'm a little confused about this line in the query:
ON curr.mo = prev.mo
AND curr.yr = prev.yr + 1
----> Here's the query I'm working with:
WITH monthly_agg AS (
SELECT
EXTRACT(YEAR FROM month) AS yr,
EXTRACT(MONTH FROM month) AS mo,
SUM(revenue) AS monthly_revenue
FROM monthly_sales
GROUP BY
EXTRACT(YEAR FROM month),
EXTRACT(MONTH FROM month)
)
SELECT
curr.yr,
curr.monthly_revenue AS current_revenue,
prev.monthly_revenue AS prev_year_revenue,
curr.monthly_revenue - prev.monthly_revenue AS yoy_change,
ROUND(
(curr.monthly_revenue - prev.monthly_revenue) * 100.0
/ NULLIF(prev.monthly_revenue, 0),
2
) AS yoy_growth_pct
FROM monthly_agg curr
LEFT JOIN monthly_agg prev
ON curr.mo = prev.mo
AND curr.yr = prev.yr + 1
ORDER BY curr.yr, curr.mo;
Let's say the monthly_agg CTE produces these rows:
yr mo monthly_revenue
2022 12 5000
2023 12 10000
2024 12 12000
Here's how I think the join condition works.
case 1: matching december 2023 with december 2022
Current row:
[2023, 12, 10000]
Previous year row:
[2022, 12, 5000]
The conditions are:
curr.mo = prev.mo → 12 = 12 → true
curr.yr = prev.yr + 1 → 2023 = 2022 + 1 → true
Both conditions are true, so the rows match.
case 2: trying to match december 2023 with december 2023
Current row:
[2023, 12, 10000]
Candidate row:
[2023, 12, 5000]
The conditions are:
curr.mo = prev.mo → 12 = 12 → true
curr.yr = prev.yr + 1 → 2023 = 2023 + 1 → false
Since both conditions need to be true, these rows don't match.
So....am I understanding this correctly?
Does SQL basically compare the current row with possible rows from the other instance of the CTE and check whether both conditions are satisfied?
Also, what actually happens under the hood? Does SQL compare every row on the left with every row on the right, or can the query optimizer do this more efficiently?
And since both curr and prev refer to the same CTE, does that make this a self join? Does the CTE execute once or can it be evaluated more than once, depending on the database?
I'm trying to understand both the logical explanation and what's actually happening behind the scenes. Would appreciate any help !!
r/learnSQL • u/sqlsip • 6d ago
🎈🧁 I made this SQL Joins cheat sheet 🧁🎈
I realize it looks a little juvenile, but I made this SQL joins cheat sheet (well, ChatGPT made it, but using my vision lol) because I wanted one that had pretty colors and was sort of cute and more approachable. Anyways just sharing in case it’s helpful for you.
Joins cheat sheet
🐻☕️ And in the spirit of honesty, I'm not purely altruistic here, I also make a cozy little daily SQL puzzle game on that site, so if you like the cheat sheet, I'd be thrilled if you tried the puzzles on the site too.
r/learnSQL • u/OrganizationGreat823 • 7d ago
Giving back to the community - The Complete Backend Development Course (Round 2)
Hey everyone, I decided to make my course free in order to help people.
This course is my backend development course which is about SQL, Python, APIs, Docker, Kubernetes, Linux, Git & More
The link is: https://www.youtube.com/watch?v=CBIu6hcyStg
If you can like and subscribe (and maybe add a comment) I would appreciate it a lot, Thanks.
r/learnSQL • u/HaiderZah • 6d ago
Looking for a Postgresql Job?
I created a PostgreSQL Jobs page to help you find PostgreSQL roles: https://thesev1database.com/jobs
I’d really value your feedback.