Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
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
Sign up free to run your codeLog inLn 1
Run your query to see results here.