<aside> 💡
This project identifies authors who have viewed at least one of their own articles. The solution demonstrates SQL skills in filtering data and removing duplicates to produce a concise and sorted result.
</aside>
The task is to find all unique author_ids where the author viewed their own article (author_id = viewer_id), and return the result sorted by id in ascending order.
The query filters the table for rows where the author_id matches the viewer_id, selects distinct author_ids, and orders the results in ascending order.
SELECT DISTINCT
author_id AS id
FROM
Views
WHERE
author_id = viewer_id
ORDER BY
id ASC;
WHERE author_id = viewer_id ensures only rows where the author viewed their own article are considered.SELECT DISTINCT author_id retrieves unique author_ids, avoiding duplicate entries.ORDER BY id ASC sorts the output by id in ascending order.