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