---
title: Answering SQL questions that require writing a solution
description: Learn the parts of an SQL question, how to answer it, how queries are evaluated and checked, and the errors you may see, such as TLE, WA, RE and CV.
---

[Skip to content](https://help.hackerearth.com/sql#main-content)

![hackerearth-logo-light](https://help.hackerearth.com/hubfs/hackerearth-logo-light.svg)

Open main navigation

Close main navigation

 Hello. How can we help you?

- There are no suggestions because the search field is empty.

1. [Help Center](https://help.hackerearth.com/)
2. [Assessments: Candidates](https://help.hackerearth.com/assessments-candidates)
3. [Question types](https://help.hackerearth.com/assessments-candidates#question-types)

# Answering SQL questions that require writing a solution

SQL questions can be in the form of MCQs or questions that require you to write a solution. This is a detailed topic about how to answer SQL questions that require you to write a solution.

## **Parts of an SQL question**

**![11-3](https://help.hackerearth.com/hs-fs/hubfs/11-3.png?width=688&height=383&name=11-3.png)**

![12-4](https://help.hackerearth.com/hs-fs/hubfs/12-4.png?width=688&height=599&name=12-4.png)

![10-Dec-16-2024-07-02-25-9878-PM](https://help.hackerearth.com/hs-fs/hubfs/10-Dec-16-2024-07-02-25-9878-PM.png?width=688&height=379&name=10-Dec-16-2024-07-02-25-9878-PM.png)

| S. No. | Description |
| --- | --- |
| 1 | Represents the problem name and contains a short description of the problem |
| 2 | Represents the problem statement of the SQL question and tasks that must be accomplished |
| 3 | Represents the input format of the question |
| 4 | Represents the output format of the question |
| 5 | Represents the information or data that is given to a program for processing |
| 6 | Represents the expected result after processing the given input as mentioned in the problem |

 

**Allowed databases**  
HackerEarth Recruit supports the following databases:

- MySQL
- PostgreSQL
- Microsoft SQL
- Oracle database

## **Answering SQL questions**

To answer the SQL questions, follow these steps:

1. Read the question and instructions carefully.
2. Write your SQL query in the code editor.
3. Click **SAVE**.
4. Click **EXECUTE & TEST**.   
   *Note*: Your query should pass through sample input and output test cases. It doesn't go through rigorous checks.
5. Click **SUBMIT**.

**Note**

- Once you have submitted your code, you cannot edit it. However, you can make new submissions. All the submissions will be judged.
- HackerEarth provides the feature of automatically submitting the answer.

You have answered an SQL question successfully.

**Evaluation**

Your code is evaluated automatically by a HackerEarth SQL service that we call SQL judge.

## **Evaluating queries**

When you submit your query, we do the following:

1. Setup a new database
2. Create tables
3. Load data specified in the test case
4. Execute your query on the newly set up database and compare the result with expected output.

If the output matches the expected result, then it is an accepted submission (AC). If the output does not match the expected result, then it is a wrong answer (WA).

## **Determining whether the solution is correct**

Each problem will have the following:

One or more input files each of which is based on the specifications mentioned in the problem statement. Each input file has a  corresponding output file.

Your program is run on each input files. To be judged as a correct submission, the output that is generated by your queries must match the output in the corresponding output files. Therefore, ensure that your statements are in order

*Notes*

- Your output files must match the output files of the problem statement irrespective of what point in the program execution the output is written.
- It is recommended that you do not read all the input before starting the output. Instead, you can print each result as you are reading through the input.

Your code will be judged as an incorrect submission if:

1. You start your query in a way other than what is mentioned in the problem statement.   
   *For example*, if your query starts with ‘Enter the number’ and it is not mentioned in the problem statement, then your script will be judged as an incorrect submission irrespective of what the rest of your queries do.
2. You use a method other than using the standard input and output streams  
   *For example*, if you use command line arguments, read from a file, open a dialog box, etc., your code will be judged as an incorrect submission.

## **Errors**

### **Time Limit Exceeded (TLE)**

Total execution time \<= (time limit\*number of input files)

In an online test, the judge allocates resources such as memory and so on for evaluating each submission. However, your submission cannot continue to run for an infinite amount of time, and therefore, the judge will stop your submission from running after a predefined (set by the recruiter) time. The TLE error will be displayed in the following cases:

- If your SQL script contains “sleep” and your queries stops executing.
- Your code terminates outside the time limit that was indicated   
  For example, if the time limit of an SQL script is 2 seconds and your script terminate on 2.001 seconds, it means: 
    - Your script exceeded the time limit by 0.001 seconds
    - The judge stopped evaluating your code after 2 seconds

- If your solution exceeds the amount of time that is allotted for the problem or test case, or your solution never finished running in the allotted time because it was stopped in between. There is no definite way to say whether the code is correct or not.

### **Wrong Answer (WA)**

This error indicates that your script ran successfully but the answer is incorrect. It will be displayed in the following cases:

- **Your SQL script contains a bug**
- You are not interpreting the problem statement correctly
- Your code matches the input test cases but does not match the output test cases

### **Runtime Error (RE)**

This error will be displayed when your program compiled successfully but exited with an error or crashed. It indicates that your query has failed to execute. You can avoid this error by ensuring that:

- Your queries are syntactically correct
- **Your script is not violating any of the problem constraints**

### **Constraints Violation (CV)**

This error will be displayed when one of the problem constraints is violated. The most common reasons for this error are as follows:

- You have created too many tables
- You have inserted too many rows inside a table

The constraints include the following:

- **Maximum tables per database will be restricted constrained and you can only create tables up to the number that is specified in the problem**
- Maximum rows per table will be restricted constrained and you can only insert rows up to the number that is specified in the problem.
- Your queries collectively have a hard time limit of 5 seconds.

- [Assessments: Recruiters](https://help.hackerearth.com/assessments-recruiters#main-content)

    - [Getting started](https://help.hackerearth.com/assessments-recruiters#getting-started)
    - [Account settings](https://help.hackerearth.com/assessments-recruiters#account-settings)
    - [Admin management](https://help.hackerearth.com/assessments-recruiters#admin-management)
    - [Creating tests automatically](https://help.hackerearth.com/assessments-recruiters#creating-tests-automatically)
    - [Creating tests manually](https://help.hackerearth.com/assessments-recruiters#creating-tests-manually)
    - [Test settings](https://help.hackerearth.com/assessments-recruiters#test-settings)
    - [Sections and question pooling](https://help.hackerearth.com/assessments-recruiters#sections-and-question-pooling)
    - [Libraries](https://help.hackerearth.com/assessments-recruiters#libraries)
    - [Multiple Choice Questions (MCQs)](https://help.hackerearth.com/assessments-recruiters#multiple-choice-questions-mcqs)
    - [Programming](https://help.hackerearth.com/assessments-recruiters#programming)
    - [Project](https://help.hackerearth.com/assessments-recruiters#project)
    - [SQL](https://help.hackerearth.com/assessments-recruiters#sql)
    - [Data science](https://help.hackerearth.com/assessments-recruiters#data-science)
    - [Machine Learning (ML)](https://help.hackerearth.com/assessments-recruiters#machine-learning-ml)
    - [DevOps](https://help.hackerearth.com/assessments-recruiters#devops)
    - [Python project questions](https://help.hackerearth.com/assessments-recruiters#python-project-questions)
    - [Automation Testing](https://help.hackerearth.com/assessments-recruiters#automation-testing)
    - [Java Project](https://help.hackerearth.com/assessments-recruiters#java-project)
    - [C# project questions](https://help.hackerearth.com/assessments-recruiters#c-project-questions)
    - [Subjective](https://help.hackerearth.com/assessments-recruiters#subjective)
    - [Approximate](https://help.hackerearth.com/assessments-recruiters#approximate)
    - [Diagram](https://help.hackerearth.com/assessments-recruiters#diagram)
    - [File upload](https://help.hackerearth.com/assessments-recruiters#file-upload)
    - [Invites](https://help.hackerearth.com/assessments-recruiters#invites)
    - [Reports](https://help.hackerearth.com/assessments-recruiters#reports)
    - [Billing](https://help.hackerearth.com/assessments-recruiters#billing)
    - [HackerEarth Reports: Admins, Tests, and Teams](https://help.hackerearth.com/assessments-recruiters#hackerearth-reports-admins-tests-and-teams)
    - [Technical Content Updates](https://help.hackerearth.com/assessments-recruiters#technical-content-updates)
- [FaceCode](https://help.hackerearth.com/facecode#main-content)

    - [FaceCode and its features](https://help.hackerearth.com/facecode#facecode-and-its-features)
    - [Scheduling interviews on FaceCode](https://help.hackerearth.com/facecode#scheduling-interviews-on-facecode)
- [Assessments: ATS integrations](https://help.hackerearth.com/assessments-ats-integrations#main-content)

    - [Integration](https://help.hackerearth.com/assessments-ats-integrations#integration)
    - [iCIMS](https://help.hackerearth.com/assessments-ats-integrations#icims)
    - [Zoho Recruit](https://help.hackerearth.com/assessments-ats-integrations#zoho-recruit)
    - [SmartRecruiters](https://help.hackerearth.com/assessments-ats-integrations#smartrecruiters)
    - [EightFold](https://help.hackerearth.com/assessments-ats-integrations#eightfold)
    - [SuccessFactors](https://help.hackerearth.com/assessments-ats-integrations#successfactors)
    - [Greenhouse](https://help.hackerearth.com/assessments-ats-integrations#greenhouse)
    - [Lever](https://help.hackerearth.com/assessments-ats-integrations#lever)
    - [Linkedin Talent Hub](https://help.hackerearth.com/assessments-ats-integrations#linkedin-talent-hub)
    - [JazzHR](https://help.hackerearth.com/assessments-ats-integrations#jazzhr)
    - [Workable](https://help.hackerearth.com/assessments-ats-integrations#workable)
    - [Recruiterbox - Trakstar Hire](https://help.hackerearth.com/assessments-ats-integrations#recruiterbox-trakstar-hire)
    - [Jobvite](https://help.hackerearth.com/assessments-ats-integrations#jobvite)
    - [Ashby](https://help.hackerearth.com/assessments-ats-integrations#ashby)
- [Assessments: Product updates](https://help.hackerearth.com/assessments-product-updates#main-content)

    - [Release notes: HackerEarth Assessment](https://help.hackerearth.com/assessments-product-updates#release-notes-hackerearth-assessment)
    - [Root Cause Analysis (RCA)](https://help.hackerearth.com/assessments-product-updates#root-cause-analysis-rca)
    - [Content updates](https://help.hackerearth.com/assessments-product-updates#content-updates)
- [Assessments: Best practices](https://help.hackerearth.com/assessments-best-practices#main-content)

    - [Recruit](https://help.hackerearth.com/assessments-best-practices#recruit)
- [SSO](https://help.hackerearth.com/sso#main-content)

    - [SSO](https://help.hackerearth.com/sso#sso)
- [Upskilling](https://help.hackerearth.com/upskilling#main-content)

    - [Introduction: Upskilling](https://help.hackerearth.com/upskilling#introduction-upskilling)
- [Assessments: Candidates](https://help.hackerearth.com/assessments-candidates#main-content)

    - [Getting started](https://help.hackerearth.com/assessments-candidates#getting-started)
    - [Test environment](https://help.hackerearth.com/assessments-candidates#test-environment)
    - [Question types](https://help.hackerearth.com/assessments-candidates#question-types)
    - [FaceCode](https://help.hackerearth.com/assessments-candidates#facecode)
    - [Feedback and queries](https://help.hackerearth.com/assessments-candidates#feedback-and-queries)
- [Problem setting for HackerEarth](https://help.hackerearth.com/problem-setting-for-hackerearth#main-content)

    - [Rate cards](https://help.hackerearth.com/problem-setting-for-hackerearth#rate-cards)
- [Campus](https://help.hackerearth.com/campus#main-content)

    - [Recruiters](https://help.hackerearth.com/campus#recruiters)
    - [Recruiter FAQs](https://help.hackerearth.com/campus#recruiter-faqs)
    - [Candidate FAQs](https://help.hackerearth.com/campus#candidate-faqs)
- [Hackathons and Hiring Challenges](https://help.hackerearth.com/hackathons-and-hiring-challenges#main-content)

    - [Hackathons](https://help.hackerearth.com/hackathons-and-hiring-challenges#hackathons)
    - [Hiring challenges](https://help.hackerearth.com/hackathons-and-hiring-challenges#hiring-challenges)
- [Frequently Asked Questions (FAQs)](https://help.hackerearth.com/frequently-asked-questions-faqs#main-content)

    - [Assessments: Recruiters](https://help.hackerearth.com/frequently-asked-questions-faqs#assessments-recruiters)
    - [GDPR compliance (Candidates)](https://help.hackerearth.com/frequently-asked-questions-faqs#gdpr-compliance-candidates)
    - [GDPR compliance (Recruiters)](https://help.hackerearth.com/frequently-asked-questions-faqs#gdpr-compliance-recruiters)
    - [General](https://help.hackerearth.com/frequently-asked-questions-faqs#general)
    - [Assessments: Candidates](https://help.hackerearth.com/frequently-asked-questions-faqs#assessments-candidates)
    - [HackerEarth Vs ChatGPT](https://help.hackerearth.com/frequently-asked-questions-faqs#hackerearth-vs-chatgpt)
- [Profiles](https://help.hackerearth.com/profiles#main-content)

    - [Profiles - Recruiter](https://help.hackerearth.com/profiles#profiles-recruiter)
- [OnScreen](https://help.hackerearth.com/onscreen#main-content)

    - [OnScreen - Interview templates](https://help.hackerearth.com/onscreen#onscreen-interview-templates)
    - [OnScreen - Sending Invites](https://help.hackerearth.com/onscreen#onscreen-sending-invites)
    - [OnScreen - Download reports](https://help.hackerearth.com/onscreen#onscreen-download-reports)
    - [OnScreen - Interview Analytics](https://help.hackerearth.com/onscreen#onscreen-interview-analytics)
    - [OnScreen - Overview](https://help.hackerearth.com/onscreen#onscreen-overview)
    - [OnScreen - Interview Proctoring Settings](https://help.hackerearth.com/onscreen#onscreen-interview-proctoring-settings)

[![hackerearth-logo-light](https://help.hackerearth.com/hubfs/hackerearth-logo-light.svg "hackerearth-logo-light")](https://www.hackerearth.com/)

##### The skills intelligence platform for the AI era. Evaluate developers, candidates, and AI agents.

<https://www.linkedin.com/company/hackerearth/> <https://twitter.com/HackerEarth> <https://www.youtube.com/channel/UCYU6nvKyRYnE5kiG9JXkXpA>

© 2026 HackerEarth · All rights reserved