6. Combine Active and Archived Users

A platform stores user information in two separate tables:

  • One for currently active users
  • One for archived users

To generate a consolidated report, the company wants a unique list of all user IDs that have ever existed on the platform.

ActiveUsers

╔═════════════╦══════════╗
║ Column Name ║   Type   ║
╠═════════════╬══════════╣
║   user_id   ║   int    ║
╚═════════════╩══════════╝
  • user_id is the primary key.

ArchivedUsers

╔═════════════╦══════════╗
║ Column Name ║   Type   ║
╠═════════════╬══════════╣
║   user_id   ║   int    ║
╚═════════════╩══════════╝
  • user_id is the primary key.
  • Some users may appear in both tables.

Write an SQL query to return all unique user_ids that appear in either ActiveUsers or ArchivedUsers. Return the result in any order.

Example 1:

Input:

ActiveUsers:

╔══════════╗
║ user_id  ║
╠══════════╣
║    1     ║
║──────────║
║    2     ║
║──────────║
║    3     ║
╚══════════╝

ArchivedUsers:

╔══════════╗
║ user_id  ║
╠══════════╣
║    3     ║
║──────────║
║    4     ║
║──────────║
║    5     ║
╚══════════╝

Output:

╔══════════╗
║ user_id  ║
╠══════════╣
║    1     ║
║──────────║
║    2     ║
║──────────║
║    3     ║
║──────────║
║    4     ║
║──────────║
║    5     ║
╚══════════╝

Explanation

User 3 appears in both tables but is shown only once in the result.

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Hints

0
 
Test Case

Input:

ActiveUsers
ArchivedUsers