Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL Set Difference for Actions
00:00
5 left

SQL Set Difference for Actions

EasySQL · PostgreSQL

Problem

Virtusa's client engagement portal records user actions separately from its audit service. Identify users who performed a case_submitted action in the portal during January 2025 but have no matching case_submitted record in the audit table during the same period.

Write a PostgreSQL query that returns each qualifying user once.

Requirements

  1. Include only case_submitted actions occurring from 2025-01-01 through 2025-01-31.
  2. Use an anti-join pattern to exclude users with a matching audit action.
  3. Return the user ID and name, ordered by user ID ascending.
  4. Do not treat other action types, actions outside January, or audit records for different users as matches.

Schema

users
ColumnTypeDescription
user_idPKINTUnique user identifier
full_nameVARCHAR(100)User's full name
portal_actions
ColumnTypeDescription
action_idPKINTUnique portal action identifier
user_idINTUser who performed the portal action
action_nameVARCHAR(50)Name of the portal action
action_atTIMESTAMPTimestamp when the portal action occurred
audit_actions
ColumnTypeDescription
audit_idPKINTUnique audit record identifier
user_idINTUser associated with the audit action
action_nameVARCHAR(50)Name of the audited action
action_atTIMESTAMPTimestamp when the audit action occurred
Tablesusersportal_actionsaudit_actions
Interviewer

Your question is SQL Set Difference for Actions. Start with the requirements and the three tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.