Distinct departments

SQL data engineering interview problem. Difficulty: beginner. Pattern: Deduplication. About 8 minutes. Free to practice.

You want a clean list of all the departments that exist in the employees table. The same department name appears many times, once for each person who works there, so you need to remove the repeats. Return each department name only once, in a column called department. Do not include a NULL department. Sort the names from A to Z.

Requirements

  • Return each department name once, even if many employees share it.
  • Use DISTINCT to remove repeated values.
  • Do not return a NULL row.
  • Sort the result by department from A to Z.

Constraints

  • The table is employees.
  • Return only 1 column: department.

Examples

Input: employees name | department Alice Chen | Engineering Bob Kumar | Engineering Omar Ali | Sales Max Reed | Sales Output: department | Engineering | Sales | Why this passes: DISTINCT collapses repeats. Marketing exists in departments but has no employee rows here.

Topics: lakebench, sql, distinct.

More SQL interview questions · All interview problems · Learn data engineering

beginner

Distinct departments

Interview-style drill: List unique department names.

Return distinct non-null `department` values from `employees`. Column: `department`. Order by `department`.