r/learnSQL • • Jun 06 '26

SQL JOINs

Hello, people! I am facing one issue, I am having troubles in understanding Left, Inner, outer joins.

I watch a video or go on datalemur, at the beginning it looks simple then when I start practicing i become confused.

What should I do? How should I practice the Joins to have a better grasp of it?

37 Upvotes

30 comments sorted by

11

u/Eleventhousand Jun 06 '26

An inner join means both tables have to have data in matching criteria for its rows to show up in the results.

An outer join means that just one table has to have data in the matching criteria for its rows to show up.

Left, Right and Full are different types of outer joins. They indicate which of the tables is the one that always has its rows show up. 99% of the time, Left is used. This means that the table in the From clause will always have its rows show up.

→ More replies (1)

4

u/squadette23 Jun 06 '26

Here is a guide to SQL joins that I wrote: https://kb.databasedesignbook.com/posts/sql-joins/

It takes a different approach compared to most existing texts:

  • LEFT JOIN is presented first, INNER JOIN second;
  • strict discipline of using ID equality comparison in ON condition;
  • we distinguish between N:1, 1:N and M:N cases of JOINs, with N:1 strictly preferred;
  • we avoid misleading wording and imagery;
  • we show a detailed explanation of overcounting in GROUP BY queries;

Try and see if it helps.

1

u/One9triple0two Jun 07 '26

Watch data with baraa

1

u/sam_vstheworld Jun 07 '26

Yes, I watch him sometimes.

2

u/Massive_Show2963 Jun 06 '26 edited Jun 06 '26

Its easier to visualize a join if you have a Entity Relational Diagram (ERD) to view.
This will show how the various tables are connected.

  • INNER JOIN: Returns records that have matching values in both tables. This is the most common type of a JOIN.
  • LEFT (OUTER) JOIN: Returns all records from the left table, and the matched records from the right table.
  • RIGHT (OUTER) JOIN: Returns all records from the right table, and the matched records from the left table.
  • FULL (OUTER) JOIN: Returns all records when there is a match in either left or right table.

I create this tutorial that will walk you through practical examples of using Entity Relationship Diagrams to model your data structure and provide a solid foundation for using JOINS.

Introduction To SQL Joins

1

u/BisonSpirit Jun 06 '26

I know exactly what you mean. In principle it makes sense but when you apply it, it becomes confusing. I’m currently on the same challenge and I think the best way to understand is to solidify your understanding of the concept, and then repetition of JOIN query’s to really understand.

At first I used Venn Diagram imagery to make sense of it, but I still get lost. The attached Gemini answer is somewhat helpful. But yes- practice practice practice

1

u/[deleted] Jun 07 '26

[removed] — view removed comment

2

u/sam_vstheworld Jun 07 '26

Sure, I would do that.

3

u/[deleted] Jun 08 '26

[removed] — view removed comment

1

u/Hudson365 Jun 08 '26

This was extremely well put thank you for sharing man!