<aside> 💡

Project Overview:

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>


Problem Description:

Table: Views

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.


Solution:

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;


Explanation:

  1. Filtering Self-Views:
  2. Removing Duplicates:
  3. Sorting Results:

Example Input and Output: