Questions
36 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?
36 / 48

How would you write a query to find customers who have orders but no payments using JOINs?

Difficulty: 5/10
LEFT JOIN, anti-join, NULL handling

Finding Customers Who Have Orders but No Payments Using JOINs

To find customers who have placed orders but have not made any payments, you can use a LEFT JOIN between orders and payments and then filter rows where the payment does not exist (IS NULL). The key idea is: JOIN all orders, then keep only those without matching payments.

Using LEFT JOIN + IS NULL

The LEFT JOIN keeps all orders even if a payment doesn't exist. Rows where payment_id is NULL indicate the order has no payment.

Alternative: Using NOT EXISTS (often faster)
Which Method Should You Use?
  1. 1

    Use LEFT JOIN + IS NULL when you also want to fetch data from the main tables (e.g., order_id).

  2. 2

    Use NOT EXISTS when you only need to check absence—it avoids row multiplication and can be more efficient.

  3. 3

    Avoid using RIGHT JOIN or FULL JOIN for this; LEFT JOIN or NOT EXISTS is cleaner and more readable.

Scenario Questions

0-2 years experience

  1. 1We have a `customers`, `orders`, and `payments` table. Write a MySQL query that returns the IDs of customers who have placed at least one order but have no corresponding payment records.
  2. 2If you run a LEFT JOIN between `orders` and `payments` and see rows where `payment_id` is NULL, what does that tell you about those orders?
  3. 3What would happen if you used an INNER JOIN instead of a LEFT JOIN in this scenario?

2-5 years experience

  1. 1Our nightly report started returning customers who actually have payments. Walk me through how you would debug the query that is supposed to find customers with orders but no payments.
  2. 2Explain why using NOT EXISTS versus LEFT JOIN … IS NULL might give different performance on a table with millions of rows, and which you would choose.
  3. 3If the `payments` table can have multiple rows per order, how would you adjust the query to ensure a customer is excluded only when any payment exists for any of their orders?

5-8 years experience

  1. 1Design an index strategy for the customers‑orders‑payments schema to support frequent anti‑join queries like 'customers with orders but no payments' at a scale of 100 M rows.
  2. 2Our batch job runs this query on a sharded MySQL cluster. What changes would you make to the query or schema to avoid cross‑shard joins and keep latency low?
  3. 3How would you rewrite the query to be safe against future schema changes, such as adding soft‑delete columns or moving payments to a separate service?

8+ years experience

  1. 1We are migrating payments to an event‑sourced microservice while keeping orders in MySQL. How would you redesign the 'customers with orders but no payments' check to work across services without tight coupling?
  2. 2Discuss the long‑term maintenance implications of using LEFT JOIN … IS NULL versus NOT EXISTS in our codebase, considering readability, optimizer behavior, and potential future DBMS migrations.
  3. 3If we need to expose this anti‑join result via a GraphQL API that aggregates data from multiple databases, what architectural patterns would you recommend to keep the query performant and consistent?

Follow-up Questions

  • What index would you add to make this query fast?
  • How would the query change if payments could be soft‑deleted?
  • Can you think of any edge cases where this query might return incorrect results?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.