SELECT with LIKE Pattern
Return employees whose first name starts with J or G.
- Filtering
Exercise brief
Understand the request
Recruiting coordinator The team is checking employees whose first names begin with J or G.
Return first_name and last_name for every employee whose first name starts with the letter J or G.
Return
- Return first_name and last_name.
Constraints
- Use LIKE pattern matching for the two prefixes.
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
employees
first_nameVARCHAR(50)last_nameVARCHAR(50)
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
LIKE handles wildcards. `%` matches zero or more characters; `_` matches exactly one character.
Hint 2
To match names starting with J use `LIKE 'J%'`. Combine the two prefixes with OR.
Hint 3
WHERE first_name LIKE 'J%' OR first_name LIKE 'G%'
Verified SQL answer
Attempt the problem first, then compare structure and reasoning—not just syntax.
Reveal solution and explanation
SELECT first_name, last_name FROM employees WHERE first_name LIKE 'J%' OR first_name LIKE 'G%';Why this works
LIKE is case-sensitive in some engines (PostgreSQL) and case-insensitive in others (MySQL by default). When you only need a prefix match, `LIKE 'J%'` is faster than functions like LEFT(first_name,1)='J' because it can use an index.
Expected result
Use this output to verify values, aliases, ordering, and row count.
| first_name | last_name |
|---|---|
| John | Smith |
| Grace | White |
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Build the next SQL skill
WHERE Clause & Filtering
Practice SQL WHERE clauses with realistic boundary, NULL, text, date, exclusion, and production-filtering problems.
Basic SQL Functions
Practice production-oriented string cleanup, numeric transformations, NULL handling, tolerant conversion, and delimiter parsing.
ORDER BY & Sorting
Practice deterministic SQL ordering with tie-breakers, custom priorities, NULL placement, expressions, joined data, aggregates, and portable top-N patterns.
Open the interactive workspace and practice across SQL topics.