Magicsheet logo

Article Views I

Easy
59.5%
Updated 6/1/2025

Article Views I

What is this problem about?

The Article Views I interview question is a common SQL/Database task. You are given a table Views containing columns: article_id, author_id, viewer_id, and view_date. The task is to find all the authors that viewed at least one of their own articles. The result should be sorted by author ID in ascending order. This Article Views I coding problem is a test of basic filtering and deduplication in a database.

Why is this asked in interviews?

Companies like Apple, Deloitte, and Google use this in their initial screening for Data Engineer or Backend roles. It checks if you understand how to compare columns within the same row, how to remove duplicate results using DISTINCT, and how to apply sorting using ORDER BY.

Algorithmic pattern used

This follows the standard Database interview pattern of "Select-Filter-Sort." You use a SELECT DISTINCT clause to get the unique IDs, a WHERE clause to filter rows where the author is the viewer, and an ORDER BY clause for the final presentation.

Example explanation

Suppose the Views table has these rows:

  • article_id: 1, author_id: 3, viewer_id: 5 (Author 3 didn't view their own article)
  • article_id: 2, author_id: 7, viewer_id: 7 (Author 7 viewed their own article - Match!)
  • article_id: 3, author_id: 7, viewer_id: 7 (Author 7 viewed their own article again)
  • article_id: 4, author_id: 8, viewer_id: 8 (Author 8 viewed their own article - Match!) The query will filter for author_id = viewer_id, then find unique authors [7, 8], and sort them.

Common mistakes candidates make

  • Forgetting DISTINCT: Returning the same author multiple times if they viewed several of their own articles.
  • Misnaming columns: Confusing viewer_id with author_id in the SELECT clause.
  • Ignoring Sort Order: Forgetting to apply ORDER BY, which is often a strict requirement in automated tests.

Interview preparation tip

Always pay attention to the sorting requirements and the need for unique results in SQL problems. Practice comparing two columns of the same table, as this is the simplest form of a "self-join" logic without actually needing a JOIN.

Similar Questions