Article Views I
Task: Find all the authors that viewed at least one of their own articles. Return the result table sorted by id in ascending order.
Table: Views
| Column Name | Type |
|---|---|
| article_id | INT |
| author_id | INT |
| viewer_id | INT |
| view_date | date |
Input: Views table:
| article_id | author_id | viewer_id | view_date |
|---|---|---|---|
| 1 | 3 | 5 | 2019-08-01 |
| 1 | 3 | 6 | 2019-08-02 |
| 2 | 7 | 7 | 2019-08-01 |
| 2 | 7 | 6 | 2019-08-02 |
| 4 | 7 | 1 | 2019-07-22 |
| 3 | 4 | 4 | 2019-07-21 |
| 3 | 4 | 4 | 2019-07-21 |
Output:
| id |
|---|
| 4 |
| 7 |
View Reference Solution & Explanation ▼
This query filters the table using basic `SELECT` and `WHERE` clauses to match the exact conditions specified in the problem.
SELECT DISTINCT author_id AS id FROM Views WHERE author_id = viewer_id ORDER BY id ASC;