Skip to main content
Database

Inner Join Tables

QueryValidateMedium

What you will learn

  • INNER JOIN drops rows where the right table has no match โ€” verify row count, not just shape, to catch silent data loss
  • Join on indexed columns only โ€” a query that works on 100 rows may table-scan at 10M. EXPLAIN before trusting test speed
  • Test NULL in join columns: INNER JOIN silently excludes them, LEFT JOIN includes with NULL โ€” know which you need

Description

Get all orders with user names.

Test Scenario

-- Your query:
SELECT o.id, u.name, o.status, o.total
FROM orders o
INNER JOIN users u ON o.user_id = u.id;

-- Expected: 5 orders with user names
-- Sample: 1 | John Doe | completed | 1349.98

Testing Tips

  • โ€ขINNER JOIN returns matching rows only
  • โ€ขON specifies join condition
  • โ€ขUse table aliases for clarity
// Playwright API Testing - Database
import { test, expect } from '@playwright/test';
test('Database query via API', async ({ request }) => {
const response = await request.post('/api/database/query', {
data: {
sql: 'SELECT * FROM users WHERE id = ?',
params: [1]
}
});
expect(response.ok()).toBeTruthy();
const { rows } = await response.json();
expect(rows.length).toBeGreaterThan(0);
});

Challenge ID: sql-inner-join

2 frameworks available