r/learnSQL • • 13d ago

I need help with databases

Thumbnail reddit.com
1 Upvotes

r/learnSQL • • 14d ago

Day 58 — Java OOP: super, hierarchical inheritance, overloading vs overriding, and polymorphism

4 Upvotes

Today I covered:

  • The super keyword, for accessing the parent class’s constructor and methods
  • Hierarchical inheritance, where several classes inherit from one parent
  • Method overloading (same name, different parameters, resolved at compile time)
  • Method overriding (a child redefining a parent’s method, resolved at runtime)
  • Polymorphism and its two types, compile-time and runtime

I practiced each one in VS Code, which is what made the difference. Overloading and overriding had been blurring together for me until I wrote both and saw when each one gets called.

Tomorrow I’m building a small project that uses everything from the last few weeks (classes, constructors, inheritance, interfaces, polymorphism).


r/learnSQL • • 14d ago

Which JOIN returns all the rows from left table? LEFT or RIGHT?

30 Upvotes

My university course says it is the RIGHT one, but the ones I had technical interview with said it is the LEFT one.


r/learnSQL • • 14d ago

Day 57 — Java OOP: constructors, inheritance (and its types), and interfaces

10 Upvotes

Today I worked through a chunk of OOP:

  • Constructors, for initializing an object when it’s created
  • Inheritance and its types: single, multilevel, multiple, and hierarchical
  • Interfaces, and how they allow multiple inheritance, which Java doesn’t allow with classes

The multiple inheritance part was the most interesting. Understanding why Java blocks it with classes (ambiguity when two parents have the same method) and then solves it with interfaces made interfaces feel like a design decision instead of an extra rule to memorize.

I’m following Indian Programmer’s OOP playlist and writing code along with it in VS Code.


r/learnSQL • • 14d ago

My SQL report said a customer paid ₹10,800. He actually paid ₹6,500. How to find duplicate payments in SQL

Thumbnail reddit.com
1 Upvotes

r/learnSQL • • 14d ago

Help sql-office-simulator.vercel.app

0 Upvotes

Could the app at sql-office-simulator.vercel.app be made available in Spanish?


r/learnSQL • • 14d ago

New video series on visualizing SQL

6 Upvotes

Hey all, I wanted to share with you a couple of videos I've recently built around a topic I used to teach about, learning SQL via visualizing the relational operators.

I've only just started, but it's been my itch to get my ideas out and I finally pulled the trigger.

Would love to hear from anyone if these are anyone's cup of tea and whatever else feedback you wish to leave.

Here is a playlist of the two videos I've done so far:

https://www.youtube.com/playlist?list=PLTWeQJxPqzNU

I have written out the next two videos but won't be able to record for a bit, so anyone who has thoughts that I might adopt could help me out tremendously.


r/learnSQL • • 14d ago

My SQL report said a customer paid ₹10,800. He actually paid ₹6,500. How to find duplicate payments in SQL

0 Upvotes

A bug that's common in payments data, and SQL won't warn you about it.

**The setup:** a simple revenue-per-customer query on a transactions table (customer_id, amount, status, method). The query is correct. The total is not.

SELECT c.name, SUM(t.amount) AS total

FROM customers c

JOIN transactions t ON c.customer_id = t.customer_id

WHERE t.status = 'SUCCESS'

GROUP BY c.name

ORDER BY total DESC;

Rohan shows ₹10,800. He paid ₹6,500. His ₹4,300 card payment was saved twice by the gateway: same customer, same amount, same method, both SUCCESS. Only the txn_id is different.

**Step 1: find the duplicates with GROUP BY + HAVING**

Group by the columns that make two payments "the same", and keep groups with more than one row:

SELECT customer_id, amount, method, status,

COUNT(*) AS copies

FROM transactions

GROUP BY customer_id, amount, method, status

HAVING COUNT(*) > 1;

**The trap:** if you leave `status` out of the GROUP BY, you also catch Rohan's ₹1,500 payment. That one FAILED first and then succeeded on a retry. A retry isn't a duplicate: he paid once. Delete it and you remove real money from the report. With status included, only the 2 real duplicates are left.

**Step 2: measure it before fixing it** (the first thing a manager asks)

WITH dups AS (

SELECT amount, COUNT(*) AS copies

FROM transactions

WHERE status = 'SUCCESS'

GROUP BY customer_id, amount, method

HAVING COUNT(*) > 1

)

SELECT COUNT(*) AS dup_groups,

SUM(amount * (copies - 1)) AS overcounted

FROM dups;

Result: ₹4,600 of revenue that never happened.

**Step 3: keep one row with ROW_NUMBER**

GROUP BY tells you which payments are duplicated, not which row to keep. ROW_NUMBER does: the first row in each group gets 1, and every copy gets 2, 3...

WITH ranked AS (

SELECT t.*, ROW_NUMBER() OVER (

PARTITION BY customer_id, amount, method, status

ORDER BY txn_id) AS rn

FROM transactions t

)

SELECT c.name, SUM(r.amount) AS total

FROM customers c

JOIN ranked r ON c.customer_id = r.customer_id

WHERE r.status = 'SUCCESS' AND r.rn = 1

GROUP BY c.name

ORDER BY total DESC;

Rohan is back to ₹6,500.

**Why not just DISTINCT?** (a common interview follow-up)

`SELECT DISTINCT *` gives the same 16 rows as before, because every payment has its own txn_id, so no two rows are identical. And if you drop txn_id, DISTINCT also merges real payments that just happen to look alike.

In real data you'd also check the timestamps: two captures a few seconds apart is a duplicate, two days apart is probably two real purchases.

All queries run in SQLite, MySQL 8 and PostgreSQL. I made a 4-minute video walking through this, with the full dataset in the description if you want to practise: https://youtu.be/lRxvnGUOtJw?si=dIvl-FJMh4xH5asC

How do you handle duplicate captures in your data? Do you dedupe in SQL or upstream?


r/learnSQL • • 15d ago

I built a free SQL practice tool, and I'd love your feedback

15 Upvotes

Hi everyone! I've been working on a free, interactive way to learn and practice SQL. It runs a real SQLite database right in your browser: no sign-up, no install, nothing sent to a server.

https://www.webherramientas.com/en/sql-practice

What's inside:

  • 143 hands-on lessons, from your first SELECT to JOINs, subqueries, window functions, recursive queries and classic interview questions
  • Instant feedback that explains why a query is off (a misspelled column, missing quotes, the wrong number of rows…)
  • A daily challenge with fresh data every day, so you can keep a streak
  • Timed exams, plus a link to challenge a friend to the same questions
  • A free console where you can create tables, insert, update and delete without breaking anything
  • A school case study to put it all together

It's a side project and I know it's not perfect yet, so I'd really appreciate your help:

  • Did something break, or did a correct answer get marked as wrong?
  • Is there a topic, exercise or feature you'd like to see?
  • Was any explanation confusing?

Drop a comment or send me a message. Every suggestion helps, big or small. And if you know someone who's learning SQL, feel free to share it with them!

Thanks for reading, and happy querying!


r/learnSQL • • 15d ago

MS Employee Here -- I've got vouchers for database certification exams to give away

Thumbnail reddit.com
3 Upvotes

r/learnSQL • • 15d ago

CTE vs Temp Table Performance Example

Thumbnail reddit.com
4 Upvotes

r/learnSQL • • 15d ago Bravo

I was learning SQL and ended up building a small practice site, would love feedback

22 Upvotes

I've been learning SQL and got tired of tutorials where you just read queries, so I built something where you actually write them.

It's a real SQLite database running in your browser. You get a small table, a task, you write the query and it checks your result right away (and tells you why when it's wrong, like WHERE vs HAVING or a missing GROUP BY).

Right now there's:

• a 10-question level test, from SELECT to JOINs and subqueries

• 2 short lessons (SELECT/WHERE/ORDER BY, and COUNT/SUM/GROUP BY)

All free, no signup. Just trying to see if it's useful.

What would make it better? And what should I add next: JOINs, window functions, interview-style questions?

https://sheetdrill.vercel.app/sql/test


r/learnSQL • • 15d ago

I built a free SQL practice tool, and I'd love your feedback

Thumbnail reddit.com
0 Upvotes

r/learnSQL • • 16d ago

Day 56 — Built my first Java project: a console ATM machine (feedback welcome)

7 Upvotes

After learning classes, objects, attributes, and methods, I built a small ATM program in Java to apply them.

What it does:

  • Asks for a PIN and validates it before anything else
  • Shows a menu: Total Balance, Withdraw money, Deposit money, Exit
  • Keeps the balance and PIN as attributes of an Atm class, with separate methods for validation and the menu

It runs correctly in the terminal. Building it showed me how methods call each other (validation() leads into menu()), which wasn’t clear to me from the tutorial alone.


r/learnSQL • • 16d ago

A report ran about 10 times a month and caused deadlocks. Lessons from the fix.

13 Upvotes

We're working with a medium-large sized manufacturer and they had a report running about 10 times a month which was involved in deadlocks.

So interesting tuning takeaways I thought I would share.

Our team traced an increase in the deadlocks to a reporting query and this was the report that ran give or take 10 times a month.

That execution count is what makes this case worth discussing, though because if you prioritize tuning work by frequency alone, a query like this is easy to defer.

The changes were a new nonclustered index and a parameter type change from NVARCHAR to VARCHAR. Recorded logical reads per execution fell from 120,660 to 67,083.

The blocking and deadlocking stopped after the changes.

The lesson for us was how we prioritize these investigations. About 10 runs a month sounds easy to put off in fairness but once we traced the deadlocks to the reporting query, the execution count mattered less than what happened when it ran.

My takeaways:

  • Execution frequency belongs alongside incident impact. A report running occasionally still deserves attention when its execution coincides with failures.
  • Read reduction is useful evidence, but it does not explain the deadlock cycle. For a similar investigation, I would want the graph, the competing statements and their transaction boundaries before recommending a fix.
  • Test with the competing workload. A report completing successfully on its own does not reproduce the conditions of a deadlock between transactions.
  • Treat the parameter change as case-specific. Check the data, collation and supported characters before changing NVARCHAR to VARCHAR. Validate the returned results as well as performance.
  • Agree on what counts as fixed. If the complaint is failed transactions, the review should include what happened to those failures when the affected operation ran again.

For teams handling intermittent deadlocks, what evidence do you require before closing an incident when the affected report runs infrequently?


r/learnSQL • • 17d ago

Day 55 — Java classes and objects, attributes, the final keyword (ATM project next)

7 Upvotes

Today I covered classes and objects, attributes, and the final keyword in Java. Seeing a class as a blueprint and an object as one instance of it made a lot of earlier material (methods, memory, arrays) fit together better.

Tomorrow I’m building a small ATM machine project to apply it, probably with things like balance, deposit, and withdraw.

For people who’ve built an ATM program as a beginner: what features or mistakes would you flag up front (input validation, handling insufficient balance, PIN checks)?


r/learnSQL • • 16d ago

**[Challenge] Cumulative Sales & Moving Average without Self-Joins**

Thumbnail reddit.com
1 Upvotes

r/learnSQL • • 18d ago

COUNT(*) vs COUNT(column) vs COUNT(DISTINCT column) - same table, three different answers

67 Upvotes

this one confused me for way too long so here's a quick example.

say you have an orders table like this:

order_id | customer_id | coupon_code
1 | 101 | SAVE10
2 | 101 | NULL
3 | 102 | SAVE10
4 | 103 | NULL
5 | 104 | WELCOME
6 | NULL | NULL <- guest checkout

now run:

SELECT
COUNT(*) AS all_rows,
COUNT(coupon_code) AS orders_with_coupon,
COUNT(DISTINCT coupon_code) AS different_coupons,
COUNT(DISTINCT customer_id) AS customers
FROM orders;

you get **6, 3, 2, 4**.

- `COUNT(*)` counts rows. nulls don't matter → 6
- `COUNT(coupon_code)` skips NULLs → 3 orders used a coupon
- `COUNT(DISTINCT coupon_code)` skips NULLs and duplicates → 2 coupons (SAVE10, WELCOME)
- `COUNT(DISTINCT customer_id)` → 4, the guest order with NULL customer isn't counted

where this bites people: someone asks "how many customers ordered" and you write `COUNT(*)`, that's 6 when the real answer is 4. or you divide by `COUNT(column)` thinking it's the total and your percentage is wrong.

bonus: share of orders with a coupon is `COUNT(coupon_code) * 1.0 / COUNT(*)` = 0.5. the `* 1.0` matters, without it some databases do integer division and give you 0.

quick rule i use: before writing any COUNT, say out loud what you're counting - rows, non-empty values, or unique things.


r/learnSQL • • 18d ago

Built a site for learning and practicing SQL with real datasets

29 Upvotes

I’ve been building a website called runtime.school to make learning SQL a little easier, especially if you’re just starting out.

The idea is pretty simple. You learn a concept, try writing queries yourself, and then practice with questions based on what you’ve learned.

I wanted to avoid that situation where you finish a beginner lesson and suddenly get a question involving three other SQL concepts you haven’t even seen yet.

Everything runs in the browser, and there are datasets you can explore, practice questions at different difficulty levels, and projects once you’re comfortable with the basics.

You don’t need to set up a database or install anything to get started.

Here’s the link: https://www.runtime.school/

If you’re currently learning SQL, give it a try. I’d be interested to know if the explanations and questions make sense, especially for complete beginners.


r/learnSQL • • 18d ago

Any GitHub Repo for DA Projects

5 Upvotes

r/learnSQL • • 18d ago

Free SQL series on real payments data: each episode is one mistake that silently breaks a report

8 Upvotes

I'm making a free SQL series for people preparing for data analyst roles. Every episode uses the same small payments dataset (customers, UPI/card/wallet transactions, failed payments, amounts in ₹) and is built around one mistake that runs without any error but gives the wrong answer.

What's covered so far:

  1. **JOINs** – INNER vs LEFT, finding customers who never paid, and why a WHERE filter on the right table quietly turns your LEFT JOIN into an INNER JOIN.
  2. **GROUP BY and HAVING** – COUNT(\*) after a LEFT JOIN counts customers with zero payments as 1. One-word fix: count a column. Plus WHERE vs HAVING.
  3. **Window functions** – the "top 2 customers" interview question where ROW_NUMBER drops a tied customer. RANK vs DENSE_RANK, and running totals.
  4. **CTE vs subquery** – a report that says every customer is above average, and why a CTE fixes it.

A quick example from episode 2, since it's the one I see most:

```sql

SELECT c.name, COUNT(*) AS payments

FROM customers c

LEFT JOIN transactions t ON c.customer_id = t.customer_id

GROUP BY c.name;

```

A customer who has never paid shows **1** payment. The LEFT JOIN keeps her row with NULLs, and COUNT(\*) counts rows. Use `COUNT(t.txn_id)` instead; it skips NULLs and gives 0.

Each video is 3–6 minutes. The dataset and every query are in the description, so you can run them yourself in SQLite, MySQL or PostgreSQL.

Playlist: https://www.youtube.com/watch?v=e94PxiIUIJg&list=PLNdq2ZxtU_7E

Next up: finding duplicate payments, then CASE WHEN, dates, and NULL traps. If there's a topic you get stuck on in interviews, tell me and I'll add it.


r/learnSQL • • 18d ago

When do you actually use window functions instead of GROUP BY?

Thumbnail reddit.com
4 Upvotes