SELECT with String Concatenation
Return full_name and email for each employee.
- Sorting
Exercise brief
Understand the request
HR systems analyst The contact export needs a single full_name field instead of separate name columns.
Build a column called full_name that combines first_name + " " + last_name. Show full_name and email, sorted alphabetically by full_name. Use a concatenation operator/function that fits the engine you are running.
Return
- Return full_name and email.
Constraints
- Use string concatenation to combine first_name and last_name with a space.
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
employees
first_nameVARCHAR(50)last_nameVARCHAR(50)emailVARCHAR(100)
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
You need three things in one query: a computed column (concat), an alias (full_name), and a sort by that alias.
Hint 2
Concatenation operator depends on the engine: SQLite/PostgreSQL/Oracle use `||`, MySQL uses CONCAT(), SQL Server uses `+` or CONCAT().
Hint 3
Concatenate first and last name with a single-space literal, alias the expression, and sort by that alias.
Verified SQL answer
Attempt the problem first, then compare structure and reasoning—not just syntax.
Reveal solution and explanation
SELECT first_name || ' ' || last_name AS full_name, email FROM employees ORDER BY full_name;Why this works
String concatenation is one of the few places where SQL dialects diverge sharply. `||` is the ANSI standard but MySQL repurposes it as logical OR (unless `PIPES_AS_CONCAT` is enabled), and SQL Server only has `+` historically. CONCAT(a, b, …) is the closest thing to a portable form.
Expected result
Use this output to verify values, aliases, ordering, and row count.
| full_name | |
|---|---|
| Alice Johnson | alice.johnson@company.com |
| Bob Wilson | bob.wilson@company.com |
| Carol Davis | carol.davis@company.com |
| David Brown | david.brown@company.com |
| Emma Taylor | emma.taylor@company.com |
| Frank Green | frank.green@company.com |
| Grace White | grace.white@company.com |
| Henry Clark | henry.clark@company.com |
| Ivy Martinez | ivy.martinez@company.com |
| John Smith | john.smith@company.com |
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.