Easy SELECT & filtering Free

SQL interview question: Combine Two Tables With UNION

Merge Active and Inactive Users

The product team needs a combined list of both active and recently deactivated users for an engagement campaign.

Combine all users from both tables. Add a 'status' column indicating 'active' or 'inactive'.

Return user_id, name, email, and status. Order by user_id.

Skills: UNION and adding literal columns

Tables

active_users 3 rows
  • user_id integer PK
  • name text
  • email text
user_idnameemail
1Alice[email protected]
2Bob[email protected]
3Charlie[email protected]
inactive_users 2 rows
  • user_id integer PK
  • name text
  • email text
user_idnameemail
4Carol[email protected]
5Dave[email protected]

Keep going