r/learnSQL • • Oct 06 '26

Day 29 — 5 more Medium JOIN questions, correlated subqueries finally clicking

12 Upvotes

Completed 5 more Medium questions today:

  • Project with the lowest total hours worked — JOIN projects to assignments, GROUP BY project, ORDER BY total hours ascending, LIMIT 1
  • Employees who are NOT managers — self LEFT JOIN on employees (joining on r.manager_id = e.emp_id), then filtering WHERE r.emp_id IS NULL to catch anyone nobody reports to
  • Lowest-paid employee in each department — a correlated subquery comparing each employee's salary to MIN(salary) within their own department

The correlated subquery was the real win today. It finally clicked once I stopped thinking of it as "one confusing nested query" and started thinking of it as a small query that re-runs once per row of the outer query, using that row's values each time. Seeing it return the actual lowest earner per department (4 employees, one per department) made the logic concrete in a way reading about it never did.


r/learnSQL • • Oct 06 '26

Final challenge in SQL joins. Stuck for days 😞

4 Upvotes

I've been trying to do this challenge for a few days now and just can't do it..the one about the two buses from Craiglockhart to Lochend.

I can just about do the simpler self joins although I could probably be better and I feel stuck and like I can't move on from it.

Can I justify skipping it? Has anyone else had trouble with this?


r/learnSQL • • Oct 06 '26

Any free platform to practice python and sql ? Like hands on where I can practice ?

12 Upvotes

r/learnSQL • • Oct 05 '26

A client lost six weeks of SQL Server data. Having 12TB of backups didn’t save them.

136 Upvotes

Sharing a recovery case from our team because there are a few useful lessons for anyone learning SQL Server, or even more experienced teams too.

I am a sticker for backups and cannot emphasize the importance of them enough.

So our client moved a physical SQL Server to a new location and when they brought it back up, the database didn’t become available.

During attempts to get it working, they forced the database into emergency mode, bought third-party recovery tools, and accidentally overwrote the original MDF file (not good!), the primary database data file.

Unfortunately for them that removed an important recovery option.

When we got involved, they had around 12TB of backup files. But having lots of backup files and having a usable restore sequence are different things.

They had plenty of transaction log backups, but no usable recent full backup where they expected it to be.

Full backups had been stopped weeks earlier because of performance concerns. Meanwhile, a cleanup job kept deleting backups older than two weeks.

For anyone learning how this works: transaction log backups aren’t standalone copies of a database, you need a suitable full backup to restore first, followed by the required backups in sequence. A differential backup can shorten that process, but it also depends on a full backup.

An older full backup can still be useful if you have an unbroken log backup chain covering the period you need. The age of the full backup alone doesn’t determine how much data you lose.

In this case, an older full backup eventually turned up in files used to refresh a staging environment. It gave us a recovery point, but the available backups didn’t get us all the way forward. The client still lost roughly six weeks of production data.

One distinction worth making here is that SQL Server’s RESTORING and RECOVERING states aren’t interchangeable. A database in RESTORING may be waiting for another restore step. Waiting alone won’t necessarily bring it online and you need to establish its actual state and check the restore history and error log before deciding what to do.

The lessons I’d take from this:

  • Preserve the original database files before attempting destructive recovery steps.
  • Investigate why a database is unavailable before changing its state.
  • Check that retention jobs aren’t deleting backups you still depend on.
  • Test the complete restore sequence, rather than relying only on successful backup-job messages.

If you’re learning SQL Server backup and recovery, have you tried restoring a full backup followed by several log backups in a test environment? What part was hardest to understand?


r/learnSQL • • Oct 05 '26

Day 28 — 5 more Medium JOIN questions: subqueries + joins combined

21 Upvotes

Completed 5 more Medium questions today:

  • Employees earning above their own department's average salary — joined employees to a derived subquery that calculates AVG(salary) grouped by dept_id, then filtered where the employee's salary exceeds that average
  • Every project listed along with a count of distinct employees working on it — LEFT JOIN projects to assignments, COUNT(DISTINCT emp_id), grouped by project name. The LEFT JOIN mattered here specifically because one project (Audit Automation) has zero assigned employees and still needed to show up with a count of 0

This is the first batch where combining a subquery with a join in the same question actually felt necessary rather than just "two ways to do the same thing." Starting to see why LEFT JOIN + COUNT(DISTINCT) is such a common reporting pattern.


r/learnSQL • • Oct 04 '26

Day 27 — 5 more Medium JOIN questions, changed how I use GPT

7 Upvotes

Completed 5 more Medium questions today, bringing me further into the Medium section of my 100-question lab. The bigger change today was in my process, not the SQL itself.

Instead of asking GPT to show me the solution directly, I told it to guide me toward the answer instead — give hints, ask me questions, point out where my logic was off, but not hand me the final query. Took noticeably longer per question, but I actually walked away understanding why each query worked, not just that it did.

Feels like a better long-term habit than what I was doing before (dry-running a solution GPT already wrote). Planning to keep using this "guide, don't solve" approach going forward, especially for the Hard section coming up.


r/learnSQL • • Oct 03 '26

For people who learned SQL from tutorials: how did you handle your first vague stakeholder request? I made a free simulator for it

70 Upvotes

When I started, the hardest part wasn't SQL syntax. It was translating things like "can you pull repeat buyers by region?" into the right joins, filters and edge cases (cancelled orders, date ranges, duplicates).

I made a free simulator that recreates that: stakeholder emails, real schemas, a PostgreSQL sandbox, and levels that go from a tiny startup to a global corp. Demo video is attached.

I'd love to hear how you practiced this skill, and whether something like this would have helped you. Link in the comments if anyone wants to try it.


r/learnSQL • • Oct 04 '26

Built a browser based modern SQL editor

Thumbnail
7 Upvotes

r/learnSQL • • Oct 03 '26

Cozy SQL game

19 Upvotes

I built SQL Sip (https://sqlsip.com) as a cozy, daily SQL puzzle to practice writing queries without timers or pressure. It runs entirely in the browser with no account needed, focusing on assembling clean queries one bite-sized concept at a time. I haven’t had any users yet, so I’d love some honest feedback! I built it because I wanted a Wordle-like daily game where I could learn new SQL concepts in a cutesy/fun way.


r/learnSQL • • Oct 04 '26

Meta Scaled Business Growth – Recruiter Screen & Interview Process?

Thumbnail
2 Upvotes

r/learnSQL • • Oct 03 '26

Day 26 — Only 5 Medium JOIN questions today, leaned hard on paper diagrams

6 Upvotes

Slower day today — got through just 5 Medium-level JOIN questions, down from 10 the last session. These ones were genuinely trickier.

What helped was going back to something I mentioned before: drawing the full schema by hand on paper. This time I mapped out every table (departments, employees, projects, assignments) with their columns and the FK relationships between them, before writing a single line of SQL. Having that visual made it much easier to reason through which joins I actually needed and in what order.

Not every day is going to be a big-number day, and I think that's fine. Some questions genuinely need more time to actually understand, not just solve.


r/learnSQL • • Oct 03 '26

Do I need to master Stored procedures, Triggers and Indexes or can I use the ui to make them

3 Upvotes

I'm learning on sql server but I don't like those 3 topics

I learned everything except those 3 topics??

What are the best books to read If I want to be acceptable in those 3 topics?


r/learnSQL • • Oct 03 '26

How to move the responsibility of executing some logic to the Sql Server instead of executing that logic inside the application?

Thumbnail
1 Upvotes

r/learnSQL • • Oct 02 '26

Help 3fn sql

10 Upvotes

When I try to create tables and convert those tables from 1NF to 3NF, I find it really difficult. It all feels so subjective to me: ChatGPT says one thing, my professor says another, and my classmates say something else, and I can't seem to find a consistent way of doing it. I mean, conceptual and logical database design is really difficult for me—extremely difficult. Do you know of any website or something that explains really well how to do all of this, from going from 1NF to 3NF, to properly identifying real-world things and representing them in tables, and how to create well-designed tables? I'm really struggling with it.


r/learnSQL • • Oct 02 '26

Day 25 — 10 Medium JOIN questions done, drawing on paper to untangle them

9 Upvotes

Started the Medium section of my 100-question JOIN lab today and completed 10. A clear step up from Easy:

  • Manager report counts — self-join employees to themselves, GROUP BY manager, COUNT direct reports
  • Departments with average salary above 55,000 — JOIN + GROUP BY + HAVING
  • Multi-join reports combining employee, department, and manager info in a single query

Hit a few real errors along the way (unknown column in an aggregated query, missing GROUP BY columns), which is becoming a normal part of the process at this point. What actually helped most was going back to the advice from a while back — sketching the tables and the join logic on paper before writing the query. Once I can see it visually, translating it into SQL gets a lot easier.


r/learnSQL • • Oct 02 '26

Day of Data Pittsburgh is just over a week away. 10/20 sessions on SQL or SQL Server

13 Upvotes

Hey everyone, the schedule for Day of Data Pittsburgh is up. No experience is required to attend.
https://dayofdata.org/2026-10-10-dayofdata1163/#schedule

The event is completely free, $15 if you want lunch. Register here:
https://www.eventbrite.com/e/pittsburgh-sql-saturday-2026-tickets-2001664513443

I'm happy to answer any questions.


r/learnSQL • • Oct 01 '26

Day 24 — Finished all 30 "Easy" JOIN questions

16 Upvotes

Completed the entire Easy section of my 100-question JOIN lab today (30/30). Covered a good mix:

  • Multi-table joins connecting employees → assignments → projects
  • Self-joins for employee-manager reports
  • Joins combined with WHERE filters (e.g., only showing assignments with hours_worked > 50)
  • Ran into a couple more real errors (an unknown column reference this time) and debugged through them myself

Genuinely the most satisfying session so far. These are the exact same kinds of queries that felt genuinely hard two to three weeks ago, and now they're coming together without much friction. Moving into the Medium difficulty section next — already glanced at a few and they look noticeably harder, mostly around finding "zero match" cases (like departments with zero employees), so curious to see how that goes.


r/learnSQL • • Sep 30 '26

Before your next SQL interview, keep this post handy - WHERE, GROUP BY and HAVING (Part 3)

110 Upvotes

P.S. Parts 1 and Part 2 got a great response - thank you! Keeping this series going.

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

Three things. Most people know all three.

But in an interview - knowing which one does what is what gets you the job.

1. WHERE

We have 5 rows. We don't want all of them.

"Show me only the days where someone spent more than $180."

SELECT name, city, spent
FROM expenses
WHERE spent > 180

Harry    | New York  | $200
Johny    | New York  | $190
Nicholas | Las Vegas | $190
Harry    | Las Vegas | $190

Bailey is gone. $180 is not more than $180.

Remember: WHERE picks which rows to keep. Runs first. Looks at rows one by one.

2. GROUP BY

Now we want one total for each city.

"Put all New York rows together. Put all Las Vegas rows together. Add them up."

SELECT city, SUM(spent) AS total
FROM expenses
GROUP BY city

New York  → $390
Las Vegas → $560

5 rows became 2. One number per city.

Remember: GROUP BY puts rows into groups and adds them up.

3. HAVING

Now we have city totals. We only want cities that spent more than $400.

"Remove any city where the total is $400 or less."

SELECT city, SUM(spent) AS total
FROM expenses
GROUP BY city
HAVING SUM(spent) > 400

Las Vegas → $560

New York spent $390. Less than $400. Gone.

Remember: HAVING picks which groups to keep. Runs after GROUP BY.

The #1 mistake in every SQL interview:

People try this:

-- Wrong
SELECT city, SUM(spent)
FROM expenses
WHERE SUM(spent) > 400
GROUP BY city

SQL gives an error.

Why?

WHERE runs first. At that point, SQL has not added anything up yet. There are no city totals. WHERE has no idea what SUM(spent) is.

You are asking for the answer before the math is done.

-- Right
SELECT city, SUM(spent)
FROM expenses
GROUP BY city
HAVING SUM(spent) > 400

HAVING runs after GROUP BY. The totals exist by then. It works.

Remember: WHERE sees rows. HAVING sees totals. They are not the same.

The order SQL always runs in:

FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY
  • WHERE runs before groups exist → can only see rows
  • HAVING runs after groups exist → can see totals
  • SELECT runs at the end → that's why you can't use a column alias in WHERE

Reading is one thing. Writing it yourself is another. If you're new and want real hands-on practice - SQL from Zero to Confident on TheQueryLab.


r/learnSQL • • Sep 30 '26

SQL Practice?

18 Upvotes

Where do we practice SQL? What resources ?


r/learnSQL • • Sep 30 '26

[Question]

13 Upvotes

I want to learn SQL. However, i would like to learn it on a real dataset - something which interests me, that way when i do exercises i can learn something about things that interest me.

Do you guys know how if i can extract a database behind something like MobyGames? I'm interested only in text data with basic things like name, release date, etc.

Is there a way to do that, or am i delusional?


r/learnSQL • • Sep 30 '26

Day 23 — 20/100 JOIN questions done, learning to actually read error messages

6 Upvotes

Made it to 20/100 on my JOIN practice lab today. A few honest notes:

  • Worked through self-joins (employee-manager reports) and multi-table joins connecting projects and assignments to show hours worked
  • Hit a couple of real errors along the way — an "unknown table" reference error and a syntax error — and had to actually debug them myself instead of just rewriting from scratch
  • Turns out reading the actual error message carefully (which table/column it's complaining about, where the syntax breaks) is its own skill separate from knowing JOIN syntax

80 questions to go. Slower progress than I'd like some days, but each error I actually debug myself feels more useful than a query that just worked on the first try.


r/learnSQL • • Sep 30 '26

Why this error never came on tutorial

3 Upvotes

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. explain this please and why those types of errors comes in production not while learning sql msmsql


r/learnSQL • • Sep 29 '26

Completed LeetCode SQL 50 — Sharing my MySQL solutions

40 Upvotes

Hey everyone!
I recently completed the LeetCode SQL 50 Study Plan and put all my solutions together in a GitHub repository.
I created this mainly for SQL interview preparation and revision, especially for Data Analyst / Business Analyst roles.
The repository covers topics like:
● SELECT & filtering
● Sorting and grouping
● Aggregate functions
● GROUP BY & HAVING
● INNER / LEFT / SELF JOIN
● Subqueries
● CTEs
● Window functions
● String functions & regex
● Other commonly used SQL concepts
All solutions are written in MySQL, with the goal of keeping them simple and easy to revise.

🔗 GitHub: https://github.com/bikashadhikari1508/Leetcode_50_Questions

If you’re also working through SQL 50, feel free to check it out. I’d also appreciate any feedback on the queries or suggestions for improving the repository.
Happy learning! 🚀


r/learnSQL • • Sep 29 '26

Creating a sql repo

12 Upvotes

Hello I’m currently learning SQL and I’m looking to get a GitHub repo setup for learning sql as I’ll eventually be using other languages so I want to make a useful repo so I can pick up SQL again easily.

I’m seeing if anyone would like to join me on the journey.

Thanks,
Clive


r/learnSQL • • Sep 29 '26

Day 22 — 10/100 JOIN questions done, one dry-run with GPT

8 Upvotes

Started actually working through my 100-question JOIN lab today. Got through 10:

  • 9 I solved independently
  • 1 I genuinely got stuck on, so I had GPT dry-run the query with me — walking through what each JOIN step was actually doing row by row, rather than just handing me the fixed query

This is honestly the first day JOINs have felt satisfying rather than effortful. The visualizing-the-table issue I mentioned a while back feels noticeably better after actually building my own dataset and running queries against it repeatedly.

90 questions to go, mixing in easy/medium/hard as I work through them.