New experience
Before attempting a database question on HackerRank, ensure that your environment is set up correctly. If you are new to the platform, take the sample test provided in your invitation email to become familiar with the interface.
Supported database languages
HackerRank supports the following database management systems:
- Microsoft SQL Server
- MySQL
- PostgreSQL
- DB2
- Oracle
You can select from the available options at the top of the editor. All queries run on standard database servers hosted in an Ubuntu environment.
Solving a database question
To solve a database question:
- Select a database question from the test dashboard and click Solve.
- Review the problem statement and any associated schema in the left panel.
- Select a supported database language from the dropdown in the coding interface.
- Write your SQL query in the code editor.
- Click Run to execute the query and validate your solution. The results panel displays pass or fail status and any error messages, if applicable.
- Click Submit when you are ready to finalize your solution.
Note: You can update your answer at any time before the test ends by clicking Modify.
Guidelines for writing and formatting queries
Database questions include one or more tables, along with schema details in the problem description. Your task is to write SQL queries that return the expected output.
-
Exact output format: Scoring is based on exact string matching. Your output must match the expected result precisely.
-
Ordering: If no specific output order is mentioned, the result may appear in any sequence.
-
Precision: Ensure numerical formats match exactly. For example, 9.0 is not equal to 9.
- Spelling and case sensitivity: Output must exactly match the format described in the prompt, including spelling and case.
Related topics
Old experience
Before solving a database question on HackerRank, ensure that your environment is set up correctly. If you haven't taken the sample test, start by familiarizing yourself with the interface.
Environment Settings: Hover over icons in the top bar to see their functions. You can switch between light or dark mode, choose your editor emulation (e.g., Vim, Emacs), enable auto-complete, and select your preferred programming language.
Supported database languages
HackerRank database questions typically involve working with one or more tables, with schemas provided in the problem statement. The available database languages are:
- MS SQL Server
- MySQL
- PostgreSQL
- DB2
- Oracle
You can select your preferred language at the top of the editor window. All queries are executed on standard database servers running on the Ubuntu platform.
Producing the Required Output
Most challenges require you to produce output in a specific format and order. If the order of rows is not specified, they can appear in any order. Key points to remember:
- String Matching: Scoring is based solely on string matching. Ensure that your output precisely matches the required format, including spelling and numeric precision.
-
Formatting: Pay close attention to the required format. For example, ensure that numeric outputs match exactly, including trailing zeros (e.g.,
9.0
is not the same as9
).
Testing and Submitting Your Code
Once you’ve written your query, you can test it by pressing the Run Query button below the editor. This will execute your code against the provided tables.
When you're confident in your solution, press Submit to finalize your answer.
Solving a database question
Here is a quick video to get you started with the Answering Database programming questions workflow.
Or, if you prefer to follow directions, here are the steps for your ready reference.
Steps
- In your Test, select the Database Engineer question or click Solve.
- Read the problem statement carefully and refer to the given data schema, if any.
- In the code editor, choose the DB language. Only the permitted languages are displayed in this list. For example, if the test setter wants to assess your DB programming skills in SQL, you may see only the Microsoft SQL Server option available to answer the question.
- Write your query in the editor and click Run Query. Your answer is validated to return the expected output.
- Click Submit answer & continue to save your answer. You can revisit this question and change your submitted answer any number of times by clicking on Modify before the Test ends.
See the following topics for detailed information: