Table: accepted_request
Log when a friend request is accepted
col_name | col_type ----------------+------------------------ sender_id | bigint recipient_id | bigint acceptance_dt | date
Structured practice, realistic datasets, and focused execution loops to help you perform with clarity in technical interviews.
230+
Interview-style coding questions
23+
Company-focused question sets
4
Practice engines: Postgres, MySQL, Python, R
| User | Score |
|---|---|
|
#1
Blake
Gold
|
115 pts
|
|
#2
Sydney
Silver
|
66 pts
|
|
#3
Greg
Bronze
|
60 pts
|
|
#4
Deeptarka
|
56 pts
|
|
#5
421
|
55 pts
|
|
#6
Juan Andrés
|
50 pts
|
|
#7
shweta
|
47 pts
|
|
#8
Michaela
|
42 pts
|
|
#9
Marieke
|
38 pts
|
|
#10
Margareta
|
38 pts
|
Anonymous Playground
Run SQL, Python, or R directly on this page. You can practice this sample without logging in.
Question 97
Table: accepted_request
Log when a friend request is accepted
col_name | col_type ----------------+------------------------ sender_id | bigint recipient_id | bigint acceptance_dt | date
Sample results
id -------------- 1000020
Official solution
POSTGRESSELECT user_id_1 AS user_id
FROM (
SELECT sender_id AS user_id_1, recipient_id user_id_2
FROM accepted_request
UNION
SELECT recipient_id AS user_id_1, sender_id user_id_2
FROM accepted_request
) X
GROUP BY 1
ORDER BY COUNT(DISTINCT user_id_2) DESC
LIMIT 1;
This query selects a user (aliasing it as "user_id") who has the most distinct accepted requests with other users.
To do this, it starts by creating a subquery that combines the sender and recipient IDs from the "accepted_request" table. It does this twice, once for each direction of the request (sender to recipient and recipient to sender). This is done using the UNION operator.
The resulting table is then grouped by the "user_id_1" column (which contains the user ID from the first column of the subquery). It counts the distinct "user_id_2" values (which contains the user ID from the second column of the subquery) for each "user_id_1". The results are then sorted in descending order based on the count of distinct "user_id_2" values.
Finally, the query selects only the first row (using LIMIT 1), which will be the user with the most distinct accepted requests with other users.
Expected results
Expected results appear after you submit.
Your results
Pick a lane, execute daily, and build interview confidence through repetition.
Track 01
Practice easy to hard questions with immediate feedback and structured progression.
Open
Track 02
Write queries and scripts against realistic business tables in your preferred engine.
Open
Track 03
Follow curated paths that map directly to data analyst, scientist, and engineer interviews.
Open
Track 04
Simulate interview pressure and sharpen how you explain your approach.
Open
Value Calculator
Enter your current salary and compare potential compensation upside against your SQLPad plan investment.
Summary
SQLPad starts at only $79/mo
Estimated annual upside
$0/year
Estimated ROI
0%
This salary estimate is based on publicly available compensation data for data scientists at top U.S. tech firms. Outcomes vary by interview performance, location, and hiring urgency.
Data engineers and machine learning engineers often earn more, so ROI can be higher for engineering-focused roles.
Ready to Begin
Use SQLPad consistently and turn interview prep into a structured system instead of a guessing game.