Prepin
Log in

Instagram Engagements

Approach / Explanation

This question necessitates an understanding of SQL, or Structured Query Language, which is a programming language utilized for managing data within a relational database management system. The question is referred to as Instagram Likes , but it lacks specific details. Therefore, it is likely a situational question where you are required to construct SQL queries. The inquiries may include prompts such as, "Write an SQL query to retrieve the Top 10 most liked posts from an Instagram database" or "Write an SQL query to calculate the average number of likes per user based on an Instagram database." In these instances, it is essential to comprehend the structure of the database you are working with. Typically, you may find tables like users , posts , likes , and so on. Key points to remember: Familiarize yourself with the database structure and schema. Consider the SQL statements you would apply based on the requirements of the question (such as SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, LIMIT, etc.). Devise an efficient query to obtain the requested information.

Suggested Answer

Let's examine a straightforward schema in which the posts table contains the fields - post_id , user_id , and likes . If we were to ask, "Write an SQL query to fetch the Top 3 most liked posts," the SQL query might appear as follows: SELECT post_id , likes FROM posts ORDER BY likes DESC LIMIT 3 ; In this example, SELECT is used to specify the columns we want to retrieve; FROM posts indicates the table from which we are extracting data; ORDER BY likes DESC organizes the records in descending order based on the likes count; and LIMIT 3 restricts the output to just the top 3 records.

Alternative Answer

Imagine a more intricate scenario where you need to identify the user who has accumulated the most likes on their posts. In this situation, you would need to use a JOIN operation. If the users table contains the fields user_id and user_name , while the posts table includes post_id , user_id , and likes , the SQL query could be structured as follows: SELECT users . user_name , SUM ( posts . likes ) as total_likes FROM users JOIN posts ON users . user_id = posts . user_id GROUP BY users . user_id ORDER BY total_likes DESC LIMIT 1 ; This query uses JOIN posts ON users.user_id = posts.user_id to merge data from the users and posts tables based on the corresponding user_id . The GROUP BY users.user_id statement organizes the likes by each user, while SUM(posts.likes) as total_likes computes the total number of likes for each user. Lastly, ORDER BY total_likes DESC LIMIT 1 retrieves the user with the highest total likes.

Question Details

Difficulty & Category

Medium
sql

Product

For CandidatesFor RecruitersCompaniesBrowse JobsInterview QuestionsDeep ProfileSkill AssessmentOpportunity Matching
Prepin.ai

© 2026 Prepin LLC · Philadelphia, PA · All rights reserved.