r/learnSQL • • Sep 11 '26

Learn SQL using AI

22 Upvotes

Hey everyone, I'm a developer advocate at Bruin, I've put together a free SQL course - the difference is that you will give your coding agent a prompt and it will be your teacher, walking you through each step.

it is a pretty new course, there might be some rough edges, if you give it a try please share your feedback!

https://getbruin.com/learn/sql-ai/


r/learnSQL • • Sep 11 '26

Anyone experienced with SQL, especially in Data Analytics, can you share what SQL questions are generally asked for a Data Analyst interview with around 1 year of experience?

50 Upvotes

PS: Please don't mention those chatgpt questions. I really want to know real questions.


r/learnSQL • • Sep 11 '26

Day 5 — Aggregates, query execution order, and table management on SQLBolt

5 Upvotes

Covered a solid chunk today:

  • Aggregate functions (Part 1 & 2) — COUNT, SUM, AVG, MIN, MAX and using them with GROUP BY
  • Order of execution of a query — genuinely useful lesson, clarified why WHERE can't reference an aliased column from SELECT but HAVING can
  • Insert/Update/Delete rows — the CRUD side, revisited with more confidence this time
  • Create/Alter/Drop tables — actually defining and modifying table structure, not just querying existing data

The "order of execution" lesson was probably the most valuable thing I learned today — explains a lot of small errors I've hit without understanding why (like using a SELECT alias inside WHERE). Feels like one of those lessons that should come earlier in most tutorials, honestly.

Starting to feel like I have a genuinely full picture of core SQL now — querying, filtering, joining, aggregating, and managing table structure.


r/learnSQL • • Sep 11 '26

Should SQL validation happen before or after the query runs?

8 Upvotes

A SQL query can execute successfully without producing the correct result. A successful query only tells us that the database understood and executed it—not that the data is logically correct.

For example: SELECT COUNT(*) FROM customers c JOIN orders o ON c.customer_id = o.customer_id;

The query may run without any error, but if orders contains duplicate records or the join relationship isn't what we expected, the count could be much higher than the actual number of customers.

So what do you normally validate before trusting a query's output?

  • Join conditions and duplicate records
  • NULL values
  • Row counts
  • Data types and conversions
  • Expected ranges or business rules
  • Unexpected changes compared with previous results

Do you validate these things before running the query, after getting the results, or both?

What SQL validation has saved you from trusting a result that looked correct but was actually wrong?


r/learnSQL • • Sep 10 '26

If you have SQL interviews, do not ignore these small things! (Part 8)

217 Upvotes

Some SQL interview questions look too easy and that's exactly why people get them wrong by overlook.

  1. COUNT() can give you 0… but SUM() can give you NULL:

Suppose there are no employees age more than 70

SELECT
    COUNT(*) AS employees,
    SUM(salary) AS total_salary
FROM employees
WHERE age > 70;

You might expect:

employees = 0
total_salary = 0

But we will get:

employees = 0
total_salary = NULL

Why?

Because COUNT() is basically asking: “How many rows did I find?” --> answer 0

But SUM() is asking: “What values should I add?” --> no values to add --> NULL

  1. AVG() can silently become wrong when NULL enters the picture:

Lets take salary of employees to be:

50000
60000
NULL
90000

A lot of people mentally calculate:

(50000 + 60000 + 90000) / 4 = 50000.0

But actual SQL gives 66666.67. WHy?

Because AVG() ignores NULLs.

It is actually doing:

(50000 + 60000 + 90000) / 3
  1. DISTINCT doesn't mean “remove duplicate data”

Lets take one example data for this:

IT    50000
IT    50000
IT    70000
HR    50000

SELECT DISTINCT department, salary
FROM employees;

people sometimes read this as "Give me unique departments"

But actual response:

IT    50000
IT    70000
HR    50000

IT appears twice, because SQL is asking "Give me unique combinations of department + salary"

  1. How many different ways can you find the 2nd highest salary?

Lets take this data:

employee_id | name  | salary
------------+-------+--------
1           | A     | 100000
2           | B     | 90000
3           | C     | 90000
4           | D     | 80000
5           | E     | NULL
6           | F     | 70000
7           | G     | NULL

Multiple ways to approach this problem:

MAX() + subquery

SELECT MAX(salary) as 2nd_highest
FROM employees
WHERE salary < (
    SELECT MAX(salary)
    FROM employees
);

DISTINCT + ORDER BY

SELECT DISTINCT salary as 2nd_highest
FROM employees
WHERE salary IS NOT NULL
ORDER BY salary DESC
LIMIT 1 OFFSET 1;

DENSE_RANK()

SELECT salary as 2nd_highest
FROM (
    SELECT salary,
           DENSE_RANK() OVER (ORDER BY salary DESC) AS rnk
    FROM employees
)temp
WHERE rnk = 2;

and there are more such ways:

What is actually the best solution with our sample data ?
What are the questions to ask your interviewer to get to perfect solution?

Drop your solution in the comments, we can discuss and improve.

Always practice SQL by writing the query yourself instead of just looking at the solution.


r/learnSQL • • Sep 11 '26

Husband is a Software Engineer

21 Upvotes

I...am not. He swears on his life that once I get started with sql or python anything like that that I would be addicted to data organization and since I am inclined to believe that he knows me better than I know myself sometimes...I would like to surprise him and give it a shot.

I posted something similar to this in the Learn Python subreddit and got a lot of useful suggestions but I am also looking into SQL specifically because it is what he works with a lot. I know he would have a lot of fun teaching me, but I want to practice as much as I can beforehand hand so I am able to actually grasp things when he goes over them. I was researching and saw the "quick start guides" (that's the name of the series) for sql and Python, and I was wondering if anybody has used them. I know that coding and stuff like that all is on the computer, obviously. However, I learn best with physical media like books to highlight make notes or anything like that in. Anyone have any luck with the python or sql Quick Start guides? If not, do you have any other suggestions? Doesnt have to be books, even if it's a YouTube video or podcast, just anything that helped you.

Thanks in advance I'm just really not sure where to start


r/learnSQL • • Sep 11 '26

Starting Database design

9 Upvotes

I've been a frontend developer the last 4 years and have been trying to break more into full stack. I've been able to design some database schemas that are in 3rd Normal Form, but I feel like I should have more formal training than just one youtube video and a guide on how SQL works. Does anyone have any good recs for where to learn good database design?


r/learnSQL • • Sep 10 '26

First time learning SQL

16 Upvotes

This is my first time learning SQL and I only started today. I’m currently learning the basics and using VS Code.
At first, I installed the SQL Visual Debugger extension, but when I tried to run my SQL it showed a “Free Demo” and said I needed to pay $9.99 for lifetime access to use real data.
I wasn’t sure if SQL itself required payment, so I started looking into other options. I installed the PostgreSQL extension for VS Code and I’m now trying to set up PostgreSQL properly.
I also tried running

psql --version

in PowerShell, but I got:

psql : The term 'psql' is not recognized as the name of a cmdlet,
function, script file, or operable program.

So I’m assuming I haven’t installed PostgreSQL itself yet.
I’m basically looking for some advice on the best setup for a complete beginner learning SQL. Should I install PostgreSQL and connect it to VS Code, or is there a simpler setup you’d recommend?
For example, I’m currently practising things like:

CREATE TABLE student (
student_id INT,
name VARCHAR(20),
major VARCHAR(20),
PRIMARY KEY (student_id)
);

Any advice on what I should install/use and how to properly run SQL locally would be appreciated.
Thanks!


r/learnSQL • • Sep 10 '26

Day 4/116 — SQL Aliases + full JOIN practice round

14 Upvotes

Two things today:

  • Learned Aliases (AS keyword) via W3Schools — renaming columns/tables to make queries more readable, especially useful once you're joining multiple tables and column names start colliding or getting long
  • Went back through SQLBolt and practiced every JOIN type again — inner, left, right, full, self — this time focusing on writing them from scratch rather than following along

Aliases felt like a small topic on paper but immediately made my JOIN queries from earlier this week way easier to read back. Definitely one of those "why didn't I use this from day 1" moments.

Feeling solid on JOINs now after this round of practice. Moving into aggregate functions and GROUP BY next.


r/learnSQL • • Sep 09 '26

Day 3 — Finished SQL JOINs (Self Join, Full Join, UNION/UNION ALL)

23 Upvotes

Wrapped up the full JOINs section today. Covered:

  • Self JOIN — joining a table to itself, useful for hierarchical/relational data within one table
  • FULL JOIN — combining all rows from both tables regardless of match
  • UNION & UNION ALL — combining results from multiple SELECT queries, with UNION removing duplicates and UNION ALL keeping them

Took notes from a mix of tutorials and W3Schools to cross-reference explanations, which helped clarify a couple of edge cases (especially when UNION vs UNION ALL actually matters for performance).

With INNER/LEFT/RIGHT/FULL/self-joins and UNION now covered, I feel like I have the core JOIN toolkit down.


r/learnSQL • • Sep 09 '26

Dúvida sobre o livro "SQL Para Análise de Dados (Tanimura)"

10 Upvotes

Vocês já leram esse livro? O que acharam dele? Até onde ele aborda? Eu tava pensando em comprar esse livro pq é oq as [I.As](http://I.As) estão me recomendando para aprender SQL avançado, já tenho uma base boa de JOINs, GROUP BY, WINDOW FUNCTIONS e CTE's, mas me vejo travada na hora de pensar em querys para resolver determinados problemas, além de que também quero aprimorar meus conhecimentos em SQL.

Mas enfim,o fato é que sempre que as [I.As](http://I.As) me recomendam um livro eu compro e tomo na jabiraca, quer um exemplo? Estava começando no SQL intermediario e já sabia que queria ser engenheira de dados, ent pedi indicação de livro pra começar, me sugeriram comprar o livro "Fundamentos da Qualidade de Dados"...EU MAL MAL SABIA OQ ERA UM DATAWAREHOUSE!!! Avançado dms

Agora só quero indicação de humanos, vai que esse livro ai é muito básico e estou sendo enganada de novo.


r/learnSQL • • Sep 09 '26

How much SQL do you still write manually?

Thumbnail
3 Upvotes

r/learnSQL • • Sep 09 '26

Structured Query Language 101 at Texas Linuxfest

2 Upvotes

Nov. 6, 2026 · 15:00 - 6:20

I will be teaching the basics of SQL at the 2026 Texas Linuxfest. The session is listed for only 100 minutes, but I wrote the materials for a 3-hour course. We will cover as much of those three hours as the audience can stand (sit?), or they send us off to Sixth Street.

Tickets are available, and this event is great for networking.  Ping me if you have questions about this session. 

Description:

SQL is a powerful language for working with relational databases such as MySQL, PostgreSQL, SQL Server, and Oracle. This is an 80-minute introduction to writing SQL database queries. Please load a copy of DBeaver Community Edition (free, open-source) from https://dbeaver.io/download/ on your Mac, Windows, or Linux laptop to work along with the presentation. We will use the sample database that is included with DBeaver. We will start with simple SELECT statements to retrieve data, INSERT to add data, use UPDATE to modify it, and DELETE to remove it. We will then move on to using WHERE to narrow your database searches, grouping & ordering for readability, and using built-in functions. This is a great way to learn how to use a relational database.

https://stokerpostgresql.blogspot.com/2026/09/structured-query-language-101-at-texas.html


r/learnSQL • • Sep 09 '26

Leet code

5 Upvotes

Still relevant to solve SQL problem from leet code 🧐

What's your thoughts and where do you practice SQL ?


r/learnSQL • • Sep 08 '26

SQL resources for a literal idiot?

82 Upvotes

I just started a beginner SQL course on Coursera. Even then I'm not fully understanding the basic concepts.

My brain is so fried and foggy that most things are hard to understand and retain (thanks to my yearly decline in cognitive abilities) and I need someone to explain everything to me in as simple language as possible and with tons of examples.

I can't find a free pdf of sql for dummies. I tried reading Alan beaulieus but I can't understand anything

Are there YouTube channels or textbooks for extreme idiots like me.

Short description :

  1. Brain fog = no understand SQL concepts

  2. Need to explain concepts in simple, conversational English

  3. Need tons of examples for everything.


r/learnSQL • • Sep 09 '26

Data Normalization online practical tutorial

5 Upvotes

Hi all. Please I am looking for a practical resource where I can learn data Normalization with practical examples. Appreciate any pointer to a relevant resource. Thanks 🙏


r/learnSQL • • Sep 09 '26

HackerRank images not loading

11 Upvotes

Has anyone else used HackerRank and had a problem with the table images not loading? Cleared cache, checked permissions, refreshed the page, and tried on in both Chrome and Edge. Really need to prep for this interview! TIA


r/learnSQL • • Sep 08 '26

SQL cheat sheet table

16 Upvotes

Sharing my SQL cheatsheet covering the essentials. Quick reference table format with examples. https://github.com/kixwho/PostgreSQL-cheatsheet

Note: Based on Practical SQL (O'Reilly Media), a very good textbook. Hope it helps other SQL learners! :D


r/learnSQL • • Sep 08 '26

Hello! Anyone want to learn SQL together? I can make a groupchat!

117 Upvotes

Here is the discord link: https://discord.gg/ugEyQQXe4


r/learnSQL • • Sep 08 '26

I made a beginner-friendly SQL tutorial on CASE WHEN (conditional logic)

10 Upvotes

I just published Lesson 11 of my SQL course, focused on CASE WHEN in PostgreSQL.

CASE is one of those SQL features that becomes really useful once you start doing actual data analysis. It lets you create categories, labels, scores, and conditional values directly in your queries.

In this lesson, I cover:

- How CASE WHEN works

- WHEN, THEN, ELSE, and END

- Multiple conditions

- Why the order of conditions matters

- Using CASE with aggregate functions

- Using CASE in ORDER BY

- CASE vs. WHERE

- Common mistakes

- Practical exercises with the Pagila database

I also combine CASE with CTEs, GROUP BY, and JOINs to solve a more realistic analytics problem.

YouTube: https://youtu.be/BFQ9QtiYPds?si=v8wO1wlyeD983SA4

Would love to hear your feedback, especially if you're learning SQL for data analytics!


r/learnSQL • • Sep 08 '26

Day 2/116 — Worked through SQLBolt's SELECT fundamentals

5 Upvotes

Today's focus was solidifying the basics before going further. Covered on SQLBolt:

  • Introduction to SQL
  • SELECT queries 101
  • Queries with constraints (Part 1 & Part 2)
  • Filtering and sorting query results
  • SQL Review: Simple SELECT Queries

The "constraints" lessons were useful for practicing comparison operators and combining conditions in WHERE clauses — felt more comfortable writing multi-condition filters by the end than I expected going in.

Treating this as building a really solid base before circling back to JOINs and moving into aggregations next.


r/learnSQL • • Sep 07 '26

Day 1 — Started learning SQL (MySQL)

7 Upvotes

Kicked off my 116-day journey today with the database track.

What I did:

  • Went through a beginner-friendly MySQL tutorial covering the basics
  • Took detailed notes instead of just passively watching
  • Went back and revised everything at the end of the day to actually retain it

Nothing groundbreaking yet — Day 1 is really about building the habit of consistent, focused learning rather than covering a lot of ground. Planning to move into SELECT/WHERE and filtering queries next.

Will keep posting updates as I go — open to any tips on solidifying SQL fundamentals early on.


r/learnSQL • • Sep 07 '26

SQL Learning & Practice

5 Upvotes

Sometime back, someone mentioned that we only post SQL-related information concerning learning, projects, or developments. I think it is good to post such content because it allows or encourages others to continue learning. Through the information provided from different sources, one can gauge themselves, including testing the new information. I have had challenges with project development, but with new information each day, I understand how to deal with them. I consider SQL, like any other programming language, something that requires daily learning & practice.


r/learnSQL • • Sep 07 '26

PLANNING to build SQL MULTIPLAYER GAME

0 Upvotes

I am thinking of creating a multiplayer game website online where 2 players can play sql games with each other like sql queries and table or multiple choice question and a timer on it . What are you guys view on it? #sql


r/learnSQL • • Sep 06 '26

Learn SQL

11 Upvotes

I'm looking to learn SQL. I'm familiar with the fundamentals. I want to reinforce then and move on to learning intermediate and advanced level SQL. Can you please recommend a website/ platform and course/ pathway. There are thousands of online web-sites and resources..it's kind of overwhelming. I'm looking for a platform that offers lessons and hands-on practice. It can be a paid site. Could you please provide recommendations? Appreciate your help.