SELECT Statements SQL Topic exerciseMediumVerified answerSQLite + PostgreSQL + MySQL + SQL Server live · 1 guided

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_nameemail
Alice Johnsonalice.johnson@company.com
Bob Wilsonbob.wilson@company.com
Carol Daviscarol.davis@company.com
David Browndavid.brown@company.com
Emma Tayloremma.taylor@company.com
Frank Greenfrank.green@company.com
Grace Whitegrace.white@company.com
Henry Clarkhenry.clark@company.com
Ivy Martinezivy.martinez@company.com
John Smithjohn.smith@company.com

Learn the concepts behind this answer

Strengthen your understanding with these targeted learning topics:

Continue practicing

SQL Practice Online

Open the interactive workspace and practice across SQL topics.