Questions
37 of 48
1What is a JOIN in MySQL, and why is it used?
2What is the difference between INNER JOIN and OUTER JOIN?
3How do you write a basic INNER JOIN query between two tables?
4What is the purpose of the ON clause in JOIN statements?
5What is the difference between using JOIN and WHERE for joining tables?
6What are LEFT JOIN and RIGHT JOIN, and how do they differ from INNER JOIN?
7What is a CROSS JOIN, and what result does it produce?
8Can you perform a JOIN without using an explicit JOIN keyword (i.e., using WHERE)? Explain.
9What happens when columns in joined tables have the same name? How do you resolve ambiguity?
10What are NATURAL JOINS and why are they generally discouraged in production code?
11Explain FULL OUTER JOIN and why MySQL does not support it directly. How can it be simulated?
12What is a SELF JOIN and when would you use it? Provide an example.
13How can you simulate an INTERSECT or EXCEPT operation using JOINs in MySQL?
14What is an ANTI JOIN and how do you implement it in MySQL?
15How do JOINs differ when using subqueries vs. derived tables?
16Performance & Optimization
17How does MySQL execute JOIN operations internally (nested loop, hash join, etc.)?
18What is the difference between a nested loop join and a hash join? Does MySQL support hash joins?
19How do indexes affect JOIN performance in MySQL?
20How can the EXPLAIN command be used to analyze JOIN performance?
21How do you optimize multi-table joins for better performance in large databases?
22What are multi-table joins, and how many tables can you join in a single query?
23What is the impact of NULL values in join conditions?
24What’s the difference between using USING(column_name) and ON in JOIN statements?
25How do you join a table with itself multiple times using aliases?
26Can you join more than one column in a JOIN condition? Give an example.
27How do you use JOINs with aggregations and conditions in MySQL?
28How to perform aggregations efficiently on joined tables in MySQL?
29How can you join tables and still include rows with no matches (using LEFT JOIN and IS NULL)?
30How can HAVING and WHERE behave differently in queries involving JOINs?
31How do GROUP BY and JOIN interact — what are the common pitfalls?
32Can you join on a calculated or derived value (for example, using a function in the ON clause)?
33How would you join three or more tables to combine customer, order, and payment data?
34What is the difference between joining normalized tables and joining denormalized ones?
35Can JOINs cause duplicate rows in results? How do you eliminate them?
36How would you write a query to find customers who have orders but no payments using JOINs?
37How do INNER JOIN and EXISTS differ logically and in performance?
38Complex & Edge Cases
39How does MySQL handle joins across databases (cross-database joins)?
40Can you JOIN temporary tables with permanent tables? Are there limitations?
41What happens when you join large datasets without appropriate indexes?
42How can you optimize memory and CPU usage when performing multiple JOINs on large tables?
43Explain a situation where replacing JOIN with a subquery improved performance.
44Does MySQL 8.0 support hash joins or batched key access joins? When are they used?
45What improvements to join optimization were introduced in MySQL 8.0 compared to earlier versions?
46How does MySQL handle join buffering and block nested loop joins?
47Can window functions be used along with JOINs? Give an example.
48What’s the difference between lateral derived tables and correlated subqueries in JOIN contexts?
37 / 48

How do INNER JOIN and EXISTS differ logically and in performance?

Logical and Performance Differences Between INNER JOIN and EXISTS

INNER JOIN and EXISTS can sometimes return similar results, but they differ in how they logically process data and how the MySQL optimizer executes them. Understanding these differences helps you choose the right method depending on your data size and query purpose.

Logical Differences
  1. 1

    INNER JOIN matches and returns rows from both tables. If multiple rows match in the second table, the result multiplies (one-to-many).

  2. 2

    EXISTS checks only whether at least one matching row exists in the subquery. It returns a boolean, not data, so no row multiplication happens.

  3. 3

    INNER JOIN returns data, while EXISTS returns only existence (true/false).

  4. 4

    EXISTS is often cleaner when you don't need columns from the joined table.

Example: INNER JOIN

If a customer has 5 orders, this query returns 5 rows (row multiplication).

Example: EXISTS

Regardless of order count, each customer appears only once because EXISTS stops searching after finding the first match.

Performance Differences
  1. 1

    EXISTS is usually faster when the joined table is large, because MySQL stops after finding the first match.

  2. 2

    INNER JOIN must process all matching rows, which can be slower in one-to-many relationships.

  3. 3

    EXISTS uses indexes efficiently—the subquery often becomes an index lookup.

  4. 4

    For small tables, the difference is minimal because MySQL may rewrite EXISTS and JOIN internally.

When to Use INNER JOIN
  1. 1

    You need columns from both tables.

  2. 2

    You expect 1-to-1 or 1-to-few relationships.

  3. 3

    You want to aggregate data from the joined table.

When to Use EXISTS
  1. 1

    You only need to check if related data exists.

  2. 2

    You want to avoid row multiplication.

  3. 3

    The joined table is large and indexed.

  4. 4

    You need better performance in NOT EXISTS queries (faster than LEFT JOIN + IS NULL in many cases).

Difficulty: 5/10
Topics: join vs subquery, query optimization, MySQL execution

Scenario Questions

0-2 years experience
  1. 1

    We have tables orders(id, customer_id) and customers(id). Write a query to list orders that have a matching customer using an INNER JOIN, then rewrite it with EXISTS. Will the result sets differ, and why?

  2. 2

    If you run an INNER JOIN between a large sales fact table and a small regions lookup table and notice the query is slow, what simple change could you try to improve performance?

  3. 3

    Suppose orders.customer_id can be NULL. How would using INNER JOIN versus EXISTS affect which rows appear in the result?

2-5 years experience
  1. 1

    Your team replaced an INNER JOIN with an EXISTS clause in a reporting query and saw the runtime halve. Walk me through why that might happen in MySQL.

  2. 2

    A query using INNER JOIN is returning duplicate rows because of a one‑to‑many relationship. How could rewriting it with EXISTS change the result and possibly the performance?

  3. 3

    During a code review you see both INNER JOIN and NOT EXISTS used for similar filters. How would you decide which to keep for readability and speed?

5-8 years experience
  1. 1

    Our nightly analytics processes billions of rows. We need to choose between an INNER JOIN‑based aggregation and an EXISTS‑based filter. What factors would you evaluate, and how would you benchmark at that scale?

  2. 2

    A legacy MySQL service has many nested INNER JOINs that cause the optimizer to pick a poor join order. How would you refactor using EXISTS or other techniques to improve the execution plan without breaking downstream services?

  3. 3

    Explain how MySQL's optimizer treats INNER JOIN versus EXISTS in terms of materialization, temporary tables, and index usage, and how that influences our choice for a high‑throughput API.

8+ years experience
  1. 1

    Your organization is standardizing query patterns across dozens of microservices. How would you create a style guide that dictates when to prefer EXISTS over INNER JOIN, considering readability, maintainability, and performance across varied workloads?

  2. 2

    We are migrating a monolithic reporting system from MySQL to a distributed SQL engine like Trino. How do the differences between INNER JOIN and EXISTS in MySQL inform the translation of queries, and what pitfalls should we watch for?

  3. 3

    Design a monitoring strategy to detect when developers introduce inefficient INNER JOINs that could be rewritten as EXISTS, and outline the tooling and alerting mechanisms you would put in place.

Follow-up Questions

  • What indexes would you add to make each approach faster?
  • How does MySQL's optimizer rewrite an EXISTS into a semi‑join?
  • Can you describe a situation where INNER JOIN would be preferable despite the performance cost?