Write a SQL query to identify duplicate active user sessions from a connection log table. Treat sessions with the same non-null user_id and device_id as duplicates, and consider only rows marked active. Exclude records with missing user or device identifiers.
user_id, device_id, active_session_count, session_ids, and earliest_connected_atuser_id, then device_id| Column | Type | Description |
|---|---|---|
| log_idPK | INTEGER | Unique connection log identifier |
| session_id | VARCHAR(30) | Identifier of the user session |
| user_id | INTEGER | Identifier of the connected user |
| device_id | VARCHAR(40) | Identifier or label for the connecting device |
| connected_at | TIMESTAMPTZ | Time at which the session connected |
| is_active | BOOLEAN | Whether the session is currently active |