← All problemsExample 1
Problem
Union Employee and Department Names
Easy- sql
Return one list of text values that holds every employee name and every department name. A value that appears in both places is listed once.
Expected columns: one column called label. Row order does not matter.
- Input
Employees(id, name, dept, salary) 1 | Alice | Sales | 50000 2 | Bob | Sales | 60000 3 | Carol | IT | 70000 4 | Dave | IT | NULL 5 | Eve | HR | 55000 Departments(dept_id, dept) 1 | Sales 2 | IT 3 | HR 4 | Finance- Output
label Alice Bob Carol Dave Eve Finance HR IT Sales- Explanation
five employee names and four department names make nine values, and none of them repeats, so all nine are listed.
Sample database
Your query runs in the browser against these tables. Column names are exact.
Departments
- dept_id
- dept
Employees
- id
- name
- dept
- salary
Customers
- customer_id
- name
- city
- signup_date
Products
- product_id
- name
- category
- price
Orders
- order_id
- customer_id
- order_date
- status
OrderItems
- order_id
- product_id
- quantity
Logins
- customer_id
- login_date
Staff
- staff_id
- name
- title
- manager_id
No automatic grading here
Run your query and check the rows against what the question asks for. Then open the model answer to compare.
SQL
Tab indents. Press Esc, then Tab to leave the editor.
Ctrl or ⌘ + Enter runs the query.
Loading the SQL engine…