The Money Trail
Concept:
Using WHERE clause to filter query results based on conditions.
Detective Indecks:
The tip said to look at Engineering. Someone in that department is making big money and leaving a suspicious paper trail.
Database:
Engineering is department_id 1. You'll want to filter the employees table to show only engineers making over 80k.
Detective Indecks:
How do I narrow it down? I don't want the whole roster, just the high rollers.
Database:
That's what WHERE is for, detective. Add conditions: `SELECT first_name, last_name, salary FROM employees WHERE salary > 80000`. Now you only see employees making over 80k.
Detective Indecks:
But I need them from Engineering specifically. How do I add that filter?
Database:
Use AND to combine conditions: `WHERE department_id = 1 AND salary > 80000`. Both conditions must be true. No exceptions.
Detective Indecks:
What about OR? What if I want multiple departments?
Database:
OR means either condition works: `WHERE department_id = 1 OR department_id = 2`. You can mix AND and OR, but use parentheses to keep your logic clean.
Detective Indecks:
Perfect. Let's filter this list and find our suspects.
Example Code:
SELECT first_name, last_name, salary FROM employees WHERE salary > 80000;
Your Assignment
Find all employees in department_id 1 (Engineering) who earn more than 80000. These are your high-value suspects.
Sql Console
sql>