#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
SQL for Testers

Types of joins : Inner joins , Non-equi Join, Natural Join, Right outer join

Inner Join

Returns only the rows where there is a match in both tables. Rows without a corresponding match in the other table are excluded.

SELECT * FROM a JOIN b ON a.id = b.a_id;

Non-Equi Join

A join whose condition uses an operator other than equals (such as <, >, or BETWEEN) — commonly used to match a value against a range, e.g. matching a salary to a salary grade table.

Natural Join

Automatically joins two tables on all columns that share the same name and data type, without needing to specify the join condition explicitly. Convenient, but risky if tables happen to share an unrelated column name.

Right Outer Join

Returns all rows from the right table, plus matching rows from the left table; unmatched columns from the left table appear as NULL.

SELECT * FROM a RIGHT OUTER JOIN b ON a.id = b.a_id;

Sample Tables to Practise On

Joins make sense only when you can see the rows. Use these three small tables for every query below.

employees.emp_idnamedept_idsalary
1Asha1032000
2Ravi2051000
3MeeraNULL45000
departments.dept_iddept_name
10QA
20Development
30Support

A third table, salary_grades, holds grade A for 30000 to 39999, grade B for 40000 to 49999, and grade C for 50000 to 69999.

What Each Join Returns Here

-- Inner join: 2 rows (Asha-QA, Ravi-Development)
SELECT e.name, d.dept_name
FROM employees e
INNER JOIN departments d ON e.dept_id = d.dept_id;

-- Right outer join: 3 rows, Support appears with a NULL name
SELECT e.name, d.dept_name
FROM employees e
RIGHT OUTER JOIN departments d ON e.dept_id = d.dept_id;

-- Non-equi join: every employee gets a grade (Asha A, Meera B, Ravi C)
SELECT e.name, e.salary, g.grade
FROM employees e
JOIN salary_grades g ON e.salary BETWEEN g.min_sal AND g.max_sal;

-- Natural join: matches on every column with the same name
SELECT name, dept_name
FROM employees
NATURAL JOIN departments;

Notice that Meera disappears from both the inner and right joins, because a NULL department never equals anything. Only the non-equi join, which does not use dept_id, includes her.

The natural join trap

The natural join above works only because dept_id is the single shared column. If a developer later adds a name column to departments for the department head, the natural join silently starts matching on both columns and returns zero rows. Nothing errors, the data just vanishes. Also note that SQL Server does not support NATURAL JOIN at all, while MySQL, PostgreSQL and Oracle do.

How Testers Use Joins in Real Work

  • Finding orphan records. Orders pointing to customers that no longer exist signal a broken delete or a missing foreign key.
  • Validating a UI screen. A report page that shows department-wise headcount should match an aggregate query you write yourself.
  • Checking data migration. Joining old and new tables on the business key reveals rows that were lost or changed during the move.
  • Verifying reference data. A right join from a lookup table shows codes that no transaction ever uses, which may point to dead options in a dropdown.
-- Orders without a valid customer
SELECT o.order_id, o.customer_id
FROM orders o
LEFT JOIN customers c ON o.customer_id = c.customer_id
WHERE c.customer_id IS NULL;

-- Headcount per department, including empty ones
SELECT d.dept_name, COUNT(e.emp_id) AS headcount
FROM employees e
RIGHT JOIN departments d ON e.dept_id = d.dept_id
GROUP BY d.dept_name;

Using COUNT(e.emp_id) instead of COUNT(*) is deliberate: it gives Support a headcount of 0 rather than 1.

Checklist Before Trusting a Join Result

  • Count rows in each table first, so you know what number to expect.
  • Check join columns for NULLs, which inner joins drop.
  • Look for duplicate keys on the "one" side, which multiply rows unexpectedly.
  • Prefer explicit ON conditions over NATURAL JOIN in test scripts.
  • Remember any right join can be rewritten as a left join by swapping table order, which many teams find easier to read.

Ready to master real-world software testing?

Learn manual and automation testing hands-on with mentor-led sessions.

Explore Course