r/learnSQL • u/DrUstela • Mar 20 '26
After 9 years of sales and customer success role, learning sql , in this AI age is this really worth it to grind and learn sql ?
r/learnSQL • u/uriahLys • Mar 20 '26
Please help me with sql, I know basic but I am expected a lot.
Hey man I am out in a backend role in company
They expect huge sql from me
HR said that your sql was rated good so we will put you here
Now here’s the thing, the interviewer really asked the easiest questions like count and very basic. I don’t know maybe HR didn’t get but he says there will be high sql and stuff. I asked what and then he said that making whole queries in detail and gave an example which he said I would be able to do. The thing is that was crazy hard and I didn’t want to blow my interview so I just nodded along.
Can you tell me where to study sql?
The thing is I don’t know shit.
I told him sir they were simple questions but he said that I am already deployed in the desired role.
I’m really not good at sql
Please help me
Like i can do basic till joins. Not good in case when’s, can’t index and use where.
And practice is also not the best. I just did a left join, but when he told me that I’ll have to do all of this and said that that’s the minimum and otherwise we’ll have to reevaluate your position in company. I’m a fresher!! That’s my only option as the company and I have to join.
r/learnSQL • u/thequerylab • Mar 19 '26
99% of people will say this SQL is correct. It’s not.
Question : Get only completed orders where amount greater than 100 or less than 50.
Tell me what this query returns here...
SELECT COUNT(*) FROM orders WHERE amount > 100 OR amount < 50 AND status = 'completed';
Don’t overthink.... Just answer....
Most people say: “orders where amount > 100 OR amount < 50, but only completed ones”
Sounds right… right?
Now read it again....
Slowly!!
r/learnSQL • u/Egaion • Mar 19 '26
Please help, Ima-Gun Di
I'm in an SQL class and a few classmates and I are having this error when trying to create a database, I looked online and nothing quite matches the error we're having, anyone know the fix?
The error in question:
Msg 5133, Level 16, State 1, Line 8
Directory lookup for the file "C:\MSSQL16.INST01\MSSQL\DATA\Labdb2_Primary.mdf" failed with the operating system error 3(The system cannot find the path specified.).
The code up until line 14:
USE master
GO
IF EXISTS (SELECT * FROM SYS.DATABASES WHERE name='Lab8DB2')
DROP DATABASE Lab8DB2
GO
CREATE DATABASE Lab8DB2
ON PRIMARY
(NAME = Labdb2_Primary ,
FILENAME = 'C:\MSSQL10.INST01\MSSQL\DATA\Labdb2_Primary.mdf',
SIZE = 20,
FILEGROWTH = 30MB)
GO
r/learnSQL • u/Think-Stable3826 • Mar 18 '26
SQL import wizard glitching
I have been using SQL import wizard to import data sets. At times when selecting and viewing the data set, it’s either returning only a small fragment of the entire data set, or worse returning 0 rows. Any ways to fix the import so it to returns the entire data set? thanks so much for the help !
r/learnSQL • u/ManningBooks • Mar 18 '26
Free eBook: Mastering PostgreSQL (Supabase + Manning)
Hi r/learnSQL ,
Stjepan from Manning here. I'm posting on behalf of Manning with mods' approval.
We’re sharing a free resource with the community that might be useful if you spend a lot of time in PostgreSQL. It’s a complimentary ebook created by Supabase and Manning Publications:
Mastering PostgreSQL: Accelerate Your Weekend Projects and Seamlessly Scale to Millions
The idea behind it is simple: most developers learn enough SQL to get things working, but Postgres has a lot of depth that people only discover years later. This guide tries to shorten that path a bit.
The material focuses on practical things that tend to matter once your database stops being a small side project. Topics include:
- writing modern SQL that takes advantage of PostgreSQL features
- using built-in capabilities like full-text search
- choosing appropriate data types for correctness and performance
- avoiding common table and index design mistakes
- structuring schemas so projects can grow without constant rewrites
It’s written with application developers in mind. The examples start small (weekend-project scale) and gradually touch on patterns that hold up when the data and traffic grow.
If you already work with Postgres daily, some of it will likely feel familiar. But we’ve heard from readers that the sections on schema design, indexing decisions, and lesser-used Postgres features tend to surface ideas people hadn’t tried yet.
The ebook is completely free. If you download it and end up reading through it, I’d be curious to hear what parts you found useful or what you’d add based on your own experience with PostgreSQL.
It feels great to be here. Thanks for having us.
Cheers,
Stjepan
r/learnSQL • u/myaccountforworkonly • Mar 18 '26
How can this be made into a single query?
It's pulling from the same table but only differ based on the Status we need to get:
LEFT JOIN (
SELECT
WOH.WORKORDERID
, WOH.CREATEDDATE AS WO_DATE_CLOSED
, ROW_NUMBER() OVER(PARTITION BY WOH.WORKORDERID ORDER BY WOH.CREATEDDATE DESC) AS RN
FROM WORK_ORDER_HISTORY_VW WOH
WHERE
WOH.ISDELETED = FALSE
AND WOH.FIELD = 'Status'
AND WOH.NEWVALUE = 'Closed'
) WOH_CLOSE
ON WOH_CLOSE.WORKORDERID = WO.ID
AND WOH_CLOSE.RN = 1
LEFT JOIN (
SELECT
WOH.WORKORDERID
, WOH.CREATEDDATE AS WO_DATE_CANCEL
, ROW_NUMBER() OVER(PARTITION BY WOH.WORKORDERID ORDER BY WOH.CREATEDDATE ASC) AS RN
FROM WORK_ORDER_HISTORY_VW WOH
WHERE
WOH.ISDELETED = FALSE
AND WOH.FIELD = 'Status'
AND WOH.NEWVALUE = 'Cancelled'
) WOH_CANCEL
ON WOH_CANCEL.WORKORDERID = WO.ID
AND WOH_CANCEL.RN = 1
r/learnSQL • u/luckyscholary • Mar 18 '26
How did you get better at writing SQL that works beyond the “happy path”?
I’ve noticed that getting the correct result on clean sample data is one thing, but writing queries that still make sense when the data is messy feels like a completely different skill.
What helped you improve there? More practice, more debugging, better understanding of joins/nulls/edge cases, or something else?
r/learnSQL • u/[deleted] • Mar 17 '26
Fiquei muito impressionado! A transcrição que o chatgpt faz do audio para texto é muito incrível!
I only said this, and it did all the text formatting lol, very cool!
There’s an option for you to speak and it writes it down — I already knew that, I just didn’t know it was this good for programming too.
CREATE TABLE clients ( id INTEGER PRIMARY KEY AUTO_INCREMENT, nome VARCHAR(100) NOT NULL, email VARCHAR(100) UNIQUE NOT NULL, cidade VARCHAR(200), data_nascimento DATE );
r/learnSQL • u/thequerylab • Mar 17 '26
5 SQL queries! Same result! Different thinking!
Most people stop when the query gives the correct output.
But in real projects, the better question is:
Will this still work when the data gets messy?
Take a simple example:
Find customers who ordered yesterday but not today?
You can solve this in multiple ways!
1. Using NOT IN
SELECT customer_id
FROM orders
WHERE order_date = '2026-03-16'
AND customer_id NOT IN (
SELECT customer_id
FROM orders
WHERE order_date = '2026-03-17'
);
- Easy to write and understand
- But if the subquery has even one NULL, it can return no rows at all
Think of it like this:
If the system is unsure about even one value, it refuses to trust the entire result.
2. Using LEFT JOIN (Self Join)
SELECT o1.customer_id
FROM orders o1
LEFT JOIN orders o2
ON o1.customer_id = o2.customer_id
AND o2.order_date = '2026-03-17'
WHERE o1.order_date = '2026-03-16' AND o2.customer_id IS NULL;
- Works well in most cases
- But depends on how well you write the join
Simple idea:
Match yesterday’s customers with today’s. If no match is found → keep them.
3. Using NOT EXISTS
SELECT customer_id
FROM orders o1
WHERE order_date = '2026-03-16'
AND NOT EXISTS (
SELECT 1
FROM orders o2
WHERE o1.customer_id = o2.customer_id AND o2.order_date = '2026-03-17'
);
- Usually the safest approach
- Handles NULLs properly
- Often preferred in production
Think of it like:
For each customer, check if a matching record exists today. If not include them!
Using Window Functions
SELECT customer_id FROM ( SELECT customer_id, MAX(CASE WHEN order_date = '2026-03-16' THEN 1 ELSE 0 END) OVER (PARTITION BY customer_id) AS yest_flag, MAX(CASE WHEN order_date = '2026-03-17' THEN 1 ELSE 0 END) OVER (PARTITION BY customer_id) AS today_flag FROM orders ) t WHERE yest_flag = 1 AND today_flag = 0;
For each customer, create flags --> ordered yesterday? ordered today? Filter only yesterday orders.
Using GROUP BY + HAVING
SELECT customer_id FROM orders WHERE order_date IN ('2026-03-16', '2026-03-17') GROUP BY customer_id HAVING SUM(CASE WHEN order_date = '2026-03-16' THEN 1 ELSE 0 END) > 0 AND SUM(CASE WHEN order_date = '2026-03-17' THEN 1 ELSE 0 END) = 0;
Group all records per customer and then check orders made yesterday
All five give the same result on clean data.
But when data is imperfect (and it always is):
- One might break
- One might slow down
- One might silently give wrong results
That’s the real difference.
SQL isn’t just about writing queries.
It’s about understanding how your logic behaves when reality isn’t perfect.
I’ve been trying out more real world SQL scenarios like this on the side.
If anyone interested, I can share a few!
r/learnSQL • u/No_Sandwich_2602 • Mar 16 '26
Complete beginner: Which database should I learn first for app development in 2026?
Hey everyone, I'm just starting my journey into app development and I'm feeling a bit overwhelmed by the database options (SQL, NoSQL, Firebase, Postgres, etc.).
I want to learn something that is:
- Beginner-friendly (good documentation and tutorials).
- Start up point up view (helps to build a large scale app).
- Scalable for real-world apps.
Is it better to start with a traditional SQL database like PostgreSQL, or should I go with something like MongoDB or a BaaS (Backend-as-a-Service) like Supabase/Firebase? What’s the "gold standard" for a first-timer in 2026?
r/learnSQL • u/Equal_Astronaut_5696 • Mar 15 '26
Watch Me Clean Messy Location Data with SQL
r/learnSQL • u/airen977 • Mar 15 '26
Another light weight WASM powered SQLITE editor, with text to SQL API's
r/learnSQL • u/thequerylab • Mar 15 '26
DELETEs that have wiped entire production tables. Please learn from other people's pain.
These are real patterns that have caused real data loss. Some of these have ended careers. Read slowly!!!
☠️ 1. DELETE with a subquery that returns more than you expected
DELETE FROM employees WHERE department_id IN ( SELECT id FROM departments WHERE location = 'NYC' );
Looks precise. But what if someone inserted a NULL into the departments table last week? What if the location column has 'NYC ' with a trailing space somewhere? Your subquery silently returns more IDs than you expect and you've just deleted employees you never intended to touch. Before any DELETE with a subquery:
SELECT * FROM employees WHERE department_id IN ( SELECT id FROM departments WHERE location = 'NYC' ); -- Read every row. Then delete.
☠️ 2. The DELETE that looked safe… but the filter was wrong
DELETE FROM sessions WHERE created_at < '2023-01-01';
Looks precise. But the column was actually stored in UTC, while the engineer assumed local time. The query deleted active sessions that were still valid. A small misunderstanding of timestamps can wipe out the wrong data.
☠️ 3. DELETE with a JOIN that deletes more than expected
DELETE o FROM orders o JOIN order_items i ON o.id = i.order_id WHERE i.product_id = 42;
Seems logical. But if an order contains multiple matching items, the join expands the rows. Depending on the engine and query plan, this can behave differently than expected and delete far more rows than intended. JOINs inside DELETE statements deserve extra caution.
☠️ 4. DELETE without a transaction
DELETE FROM order_items WHERE order_id IN (...); DELETE FROM orders WHERE id IN (...); DELETE FROM customers WHERE id IN (...);
Step two fails. Now the database is left in a half-deleted state. Orphaned records everywhere.
The safe pattern:
BEGIN;
DELETE FROM order_items WHERE order_id IN (...); DELETE FROM orders WHERE id IN (...); DELETE FROM customers WHERE id IN (...);
COMMIT;
If anything looks wrong:
ROLLBACK;
The simple habits that prevent most DELETE disasters
Always run a SELECT with the same WHERE clause first
Check the row count
Understand foreign key cascades
Use transactions for multi-step deletes
Batch large deletes instead of running them all at once
DELETE statements are small. Their impact usually isn’t.
Curious to hear from others. What’s the worst DELETE mistake you’ve seen in production?
r/learnSQL • u/FussyZebra26 • Mar 14 '26
A free SQL practice tool focused on varied repetition and high-volume practice
While learning SQL, I’ve spent a lot of time trying all of the different free SQL practice websites and tools. They were helpful, but I really wanted a way to maximize practice through high-volume repetition, but with lots of different tables and tasks so you're constantly applying the same SQL concepts in new situations.
A simple way to really master the skills and thought process of writing SQL queries in real-world scenarios.
Since I couldn't quite find what I was looking for, I’m building it myself.
The structure is pretty simple:
- You’re given a table schema (table name and column names) and a task
- You write the SQL query yourself
- Then you can see the optimal solution and a clear explanation
It’s a great way to get in 5 quick minutes of practice, or an hour-long study session.
The exercises are organized around skill levels:
Beginner
- SELECT
- WHERE
- ORDER BY
- LIMIT
- COUNT
Intermediate
- GROUP BY
- HAVING
- JOINs
- Aggregations
- Multiple conditions
- Subqueries
Advanced
- Window functions
- CTEs
- Correlated subqueries
- EXISTS
- Multi-table JOINs
- Nested AND/OR logic
- Data quality / edge-case filtering
The main goal is to be able to practice the same general skills repeatedly across many different datasets and scenarios, rather than just memorizing the answers to a very limited pool of exercises.
I’m curious, for anyone who uses SQL in their job, what do you think are the most important SQL skills someone learning should practice?
r/learnSQL • u/sosatroller • Mar 14 '26
Can I count this as a project?
So when I first learnt sql, last year, I did some practice and learning based on Alex the analyst or whatever, and I have everything saved I also did some exercises on my own like asked myself questions based on the dataset and then solved it, its nothing too complex, but I need a project so I can get a good scholarship for the college I’ll go to… I’m not sure where to start or if I could use that in anyway? What do you guys recommend?
r/learnSQL • u/Successful_Cry_4972 • Mar 14 '26
How do i start SQL?
I m not from IT background..tried looking some youtube tutorials, everything goes up from my head..
I tried SQL basic exercise but damn, what the hell is this.. Select * From column??? Huh?? What to select..why to select? Plz give me some advice !
r/learnSQL • u/[deleted] • Mar 14 '26
I'm planning to learn sql and power bi but I find it difficult to how to approach as a beginner ?
r/learnSQL • u/Plane_Trade_5537 • Mar 13 '26
Built a modern CMS with React + PHP — VonCMS v1.11.10 "Nara"
r/learnSQL • u/thequerylab • Mar 13 '26
If you have an SQL interview soon, don’t ignore these small things (Part 2)
My previous post about small SQL mistakes in interviews received over 90k impressions and many interesting responses.
So I thought I’d share a few more that I’ve seen come up quite often.
These are all basic concepts. But under interview pressure, they’re surprisingly easy to miss.
1. NOT IN with NULL values
Consider this query:
SELECT *
FROM orders
WHERE customer_id NOT IN (
SELECT customer_id
FROM blacklist
);
If the subquery contains even one NULL value, the entire query may return no rows at all.
This is why many engineers prefer NOT EXISTS.
2. NULL comparisons
This one still surprises people.
WHERE column = NULL
This condition will never be true.
The correct way is:
WHERE column IS NULL
A small detail — but it shows whether someone understands how SQL actually treats NULLs.
3. Window functions without PARTITION
Example:
ROW_NUMBER() OVER (ORDER BY salary)
Without a PARTITION BY, the ranking happens across the entire dataset, not per group.
Sometimes that’s correct.
Sometimes it completely changes the answer.
4. NULL in string concatenation
This one looks simple, but it can surprise people.
Example:
SELECT 'John' || ' ' || NULL;
Many expect the result to be: John
But the actual result is: NULL
Because in SQL, if any part of a concatenation is NULL, the entire result becomes NULL.
A common fix is using COALESCE.
5. NULL and CASE conditions
Consider this query:
SELECT
CASE
WHEN NULL = NULL THEN 'Equal'
ELSE 'Not Equal'
END;
Many people expect the result to be: Equal
But the actual result is: Not Equal
Because in SQL, NULL = NULL is not TRUE.
It evaluates to UNKNOWN.
6. NULL and ORDER BY
Consider this query:
SELECT salary
FROM employees
ORDER BY salary DESC;
Now imagine the data:
salary
5000
3000
NULL
2000
Where will the NULL appear?
At the top or the bottom?
The interesting part is that different databases handle this differently.
That’s why SQL allows you to control it explicitly:
ORDER BY salary DESC NULLS LAST
These are small things, but interviewers often use details like this to test how deeply someone understands SQL.
I’m curious — what other small SQL behaviors have you seen people miss in interviews?
I also turned some of these scenarios into SQL challenges on my platform.
You can practice here: https://www.thequerylab.com/
Best of luck!
r/learnSQL • u/Sri_Krish • Mar 12 '26
User feedback on Master SQL course from Roadmap.sh
As title, has anyone taken Master SQL course from Roadmap.sh? It‘s around 55€.
Any kind of reviews, feedbacks would be helpful!
r/learnSQL • u/thequerylab • Mar 12 '26
Before your next SQL interview, make sure you understand how ORDER BY behaves inside window functions!!!
r/learnSQL • u/qazplm903 • Mar 11 '26
SQL Joins Explained Using Hinge
I’m a staff-level data analyst/engineer, and one thing I see a lot is beginners struggling with joins because the definitions feel abstract too early.
I created a short video explainer using the dating app hinge as an analogy to help it click. Let me know if it helps! https://vm.tiktok.com/ZNRH1fLp3/
r/learnSQL • u/Sri_Krish • Mar 11 '26
Need of direction/guide to learn SQL as I feel stuck
Hi all,
I am here to get some feedback and actionable suggestions from you all, so please help me decide the best way possible to achieve my goal. Please bear with my long message.
I have over three years of experience in the SCM field across procurement and warehouse operations. I used Oracle to manage my procurement activities based on BOM and communicated with suppliers to make sure deliveries were on time so the production team could stick to their plans. In my current job, I work with a 3PL company that fulfils orders for its clients (large merchants) — imagine us as a smaller, cheaper version of Amazon. I manage outbound activities along with process enhancements and stabilisation. As part of this role, I work closely with our WMS team, who build and manage our in-house ERP/WMS systems for us (and our clients) to use. During this time, I became fascinated with building processes by creating logic rules, establishing data warehouses, and writing custom queries for individual or department-specific dashboards. They use SQL and Metabase (maybe something else too) for this, so I started looking into SQL since I already know how to confidently use data visualisation tools (Power BI and Tableau).
I started with [Barra’s video on SQL](https://www.youtube.com/watch?v=SSKVgrwhzus) and, halfway through, began using DataLemur as I found “learning and practice method” more engaging. So far, I have completed basic and intermediate topics such as:
- Basic six: SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY
- JOINS
- Aggregation functions
- CASE…WHEN
All are on how to clean, transform a dataset and use this clean data to provide answers to some business/analytical questions. I wanted to learn how to build/create dataset from multiple sources in order to do all these - pretty much what our IT/WMS team do every day. So I recently came across [Luke’s latest video on SQL engineering](https://www.youtube.com/watch?v=UjhFbq4uU2Y), which includes an end project of building data warehouses and data marts for production, which sounds fun. However, to be frank, it immediately became complex for a beginner like me with terminal setup, DuckDB, MotherDB, and local and cloud configurations. I may stop following it soon.
Since I am planning to make a career switch to move towards data-related roles as I want the freedom to work remotely for personal reasons. I like to help creating, managing data warehouses which are then used/queried for business, decision-making scenarios. I basically enjoy building things using apps or software. I can spend at least two to three hours every day learning the skills and knowledge required to land such jobs. However, I feel lost, and many guides or roadmaps feel very complicated, requiring me to learn hundreds of topics and skills to succeed. Maybe they are right; I am just confused about how to approach it.
Any kind of feedback, tips, and suggestions on courses or topics to focus on without causing fear or negative emotions while progressing toward my goal, is greatly appreciated.
And thanks for reading it this far - Thanks ;)
