Q2 of 26 · SQL

Write a SELECT query to find all orders placed by a specific customer that are in 'pending' status.

SQLJuniorsqlselectwherebasics

Short answer

Short answer: SELECT * FROM orders WHERE customer_id = 42 AND status = 'pending';

Detail

This is the foundation of any SQL validation. The query filters rows using AND to combine two conditions:

SELECT *
FROM   orders
WHERE  customer_id = 42
  AND  status = 'pending';

In a real QA context you'd usually be more specific about columns rather than SELECT *:

SELECT order_id, created_at, total_amount, status
FROM   orders
WHERE  customer_id = 42
  AND  status = 'pending'
ORDER BY created_at DESC;

Common WHERE clauses in QA work:

  • = exact match
  • != or <> not equal (useful for "status should NOT be 'deleted'")
  • IN ('a', 'b') multiple allowed values
  • IS NULL / IS NOT NULL for nullable columns
  • BETWEEN for date or numeric ranges
  • LIKE '%pattern%' for partial string matches

// EXAMPLE

-- Find pending orders for customer 42
SELECT order_id, created_at, total_amount, status
FROM   orders
WHERE  customer_id = 42
  AND  status      = 'pending'
ORDER BY created_at DESC;

// WHAT INTERVIEWERS LOOK FOR

Correct syntax, use of AND to combine filters, and awareness of column selection over SELECT *.