SQL Joins Explained with Simple Examples for Beginners
A SQL join combines rows from two or more tables using a related column. INNER JOIN returns only matching rows, LEFT JOIN keeps all rows from the left table, RIGHT JOIN keeps all from the right, and FULL JOIN keeps everything from both tables, filling gaps with NULL.
The idea behind joins
Databases split data into tables to avoid repetition. For example, a students table holds names and a marks table holds scores, linked by a student ID. A join brings them together in one result so you can see each name next to a score.
The main join types
- INNER JOIN: only students who have marks
- LEFT JOIN: all students, with marks where available, NULL where not
- RIGHT JOIN: all marks, even if a student record is missing
- FULL JOIN: everything from both sides (not available in every database, such as older MySQL setups)
- CROSS JOIN: every combination of rows, used rarely
LEFT JOIN is very helpful for finding missing data, such as students with no marks, by filtering rows where the right side is NULL.
Common beginner mistakes
- Forgetting the ON condition, which produces a huge cross product
- Joining on the wrong column
- Using SELECT * and getting duplicate column names
- Putting a filter in WHERE that accidentally turns a LEFT JOIN into an INNER JOIN
- Ignoring indexes on join columns when tables are large
How to practise
Create two small tables, such as customers and orders, add a few rows including some unmatched ones, and run each join type. Compare the outputs row by row. Draw the tables on paper first; it makes the logic clear.
Once joins feel natural, subqueries and grouping become much easier. KIT Computer Education in Madurai teaches these in its 2-month SQL course, and you can ask for a free demo class to see the approach.
Frequently asked questions
What is the difference between INNER and LEFT JOIN?
INNER JOIN returns only rows with matches in both tables. LEFT JOIN returns every row from the left table and fills missing matches with NULL.
Is JOIN slower than a subquery?
Not necessarily. Performance depends on indexes, data size and the database optimiser, so test both on your own data.
How many tables can I join?
You can join many tables in one query, though readability suffers if there are too many. Build the query step by step.
Visit KIT Computer Education, Thirunagar, Madurai or call +91 78688 50980.
Book a free demo class