Locate an Employee by First Name
Find the employee whose first name is exactly John.
- Filtering
Exercise brief
Understand the request
HR analyst A payroll exception was filed for an employee identified by first name.
Return the employee whose first name exactly matches John.
Return
- Return first_name, last_name, salary, department_id in this exact left-to-right order.
Constraints
- Use exact equality on first_name; do not normalize or pattern-match the name.
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
employees
first_nameVARCHAR(50)last_nameVARCHAR(50)salaryINTEGERdepartment_idINTEGER
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
Use an equality predicate when one text value must match exactly.
Hint 2
Place WHERE after FROM, compare first_name with `=`, and write the target name as a quoted text literal.
Hint 3
SELECT first_name, last_name, salary, department_id FROM employees WHERE first_name = /* exact text literal */;
Verified SQL answer
Attempt the problem first, then compare structure and reasoning—not just syntax.
Reveal solution and explanation
SELECT first_name, last_name, salary, department_id FROM employees WHERE first_name = 'John';Why this works
The equality predicate keeps rows whose first_name compares equal to the target literal. A value with different case, trailing spaces, or a different collation can behave differently from an apparent visual match. PostgreSQL ordinary `=` and SQLite BINARY comparisons are case-sensitive, while MySQL and SQL Server behavior depends on collation; use the dedicated case-matching lesson when case should be ignored.
Success check
Only the exact John record is returned.
Expected result
Use this output to verify values, aliases, ordering, and row count.
| first_name | last_name | salary | department_id |
|---|---|---|---|
| John | Doe | 75000 | 1 |
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Build the next SQL skill
SELECT Statements
Select columns, filter rows, remove duplicates, and order query results.
CASE Statements & Conditional Logic
Build NULL-aware classifications, precedence-safe decisions, flags, scores, and guarded calculations with portable CASE expressions.
Date Operations & Time-Based Analytics
Practice date arithmetic, safe timestamp ranges, calendar bucketing, dense time series, rolling windows, growth, and cohort analysis.
Open the interactive workspace and practice across SQL topics.