Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
Safe SQL in Java CRUD
00:00
5 left

Safe SQL in Java CRUD

MediumSQL · PostgreSQL

Problem

In the code-complete exercise on an existing Java/JDBC CRUD codebase, implement the required database access without introducing SQL injection (parameterized PreparedStatement rather than string formatting).

Asked in the Code complete screen stage. Practical code-complete screen, candidate chose Java.

Write a SQL query that returns active orders for a given customer email domain and minimum order amount.

Output

  1. One row per matching order
  2. Columns: order_id, customer_name, customer_email, order_total, order_status
  3. Include only orders whose status is active, whose total is at least the requested minimum, and whose customer email ends with the requested domain
  4. Ignore rows where customer_email is NULL
  5. Sort by order_total descending, then order_id ascending

Schema

customers
ColumnTypeDescription
idPKINTPrimary key for the customer
full_nameVARCHAR(120)Customer full name
emailVARCHAR(255)Customer email address
is_activeBOOLEANWhether the customer account is active
orders
ColumnTypeDescription
idPKINTPrimary key for the order
customer_idINTCustomer who placed the order
total_amountNUMERIC(10,2)Order total amount
statusVARCHAR(20)Order status
created_atDATEOrder creation date
Tablescustomersorders
Interviewer

Your question is Safe SQL in Java CRUD. Start with the requirements and the two 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.