HackerRank certification guide

HackerRank SQL (Basic) Certification Solutions: All 5 Questions Explained

Last checked 5 min read

The HackerRank SQL (Basic) certification is a free 30-minute test with 2 SQL questions. As far as I and other people who have taken it can tell, those 2 questions come from a pool of 5. This page covers all five, with a MySQL query for each that I have tested on my own sample data.

I passed this test myself (my certificate), and my answers have been on GitHub since 2022, where the repo has passed 100 stars. This page is the updated, explained version of that repo.

Read the explanation for each query, not just the code. The test is short, and you’ll want to recognise the pattern rather than hunt for the right file to paste.

What the test looks like

  • Time: 30 minutes.
  • Questions: 2 SQL queries, picked from the 5 below.
  • Database: I wrote every answer here in MySQL. If the editor gives you a choice of database, pick MySQL so these queries work as written.
  • Topics: simple SELECT queries, joins between two tables, WHERE conditions and sorting. Nothing in the pool needs window functions or subqueries.
  • Cost: free.

Every question gives you two tables. You join them and filter. If you can write an INNER JOIN with a WHERE clause and an ORDER BY without looking anything up, you’re most of the way there.

How to prepare

  1. Do the Basic Select, Basic Join and Aggregation problems in HackerRank’s own SQL practice section. They run in the same kind of editor as the test, so you get used to how it shows errors and output.
  2. Learn the difference between > and >= in plain English: “more than” means >, and “or more” or “at least” means >=. Three of the five questions turn on this.
  3. Know how MySQL joins strings: CONCAT(). Not +, not ||. One question depends on it.
  4. Work through the five questions below. For each one, try writing the query yourself before you open the solution.

Student Analysis

Return the roll number and name of every student whose marks in three subjects add up to less than 100. The marks are three columns in one row, so you add them with +. Exactly 100 does not count.

student-analysis.sqlMySQL
SELECT s.roll_number, s.name
FROM student_information s
JOIN examination_marks e ON e.roll_number = s.roll_number
WHERE e.subject_one + e.subject_two + e.subject_three < 100;

Full explanation →

Country Codes

Return every customer’s id, name and phone number with a + and their country code in front, sorted by customer_id. The trap is the string joining: in MySQL you need CONCAT(), because + adds numbers and || means OR.

country-codes.sqlMySQL
SELECT c.customer_id, c.name,
       CONCAT('+', cc.country_code, c.phone_number) AS phone_number
FROM customers c
LEFT JOIN country_codes cc ON cc.country = c.country
ORDER BY c.customer_id;

Full explanation →

Student Advisor

Return the students whose advisor is a man earning more than 15,000 or a woman earning more than 20,000. Each gender has its own salary limit, so write two bracketed conditions joined by OR. Watch out: at least one popular GitHub repo has the Merit Rewards query saved as its Student Advisor answer.

student-advisor.sqlMySQL
SELECT s.roll_number, s.name
FROM student_information s
JOIN faculty_information f ON f.employee_ID = s.advisor
WHERE (f.gender = 'M' AND f.salary > 15000)
   OR (f.gender = 'F' AND f.salary > 20000);

Full explanation →

Profitable Stocks

Return the code of every stock whose predicted price tomorrow is higher than its price today, in ascending order. Equal prices are not a profit, so use >, and don’t forget the ORDER BY.

profitable-stocks.sqlMySQL
SELECT t.stock_code
FROM price_today t
JOIN price_tomorrow n ON n.stock_code = t.stock_code
WHERE n.price > t.price
ORDER BY t.stock_code ASC;

Full explanation →

Merit Rewards

Return the id and name of every HR employee whose bonus last quarter was 5000 or more. “Or more” means >= 5000, and the division check should be an exact match, not LIKE 'HR%'.

merit-rewards.sqlMySQL
SELECT e.employee_ID, e.name
FROM employee_information e
JOIN last_quarter_bonus b ON b.employee_ID = e.employee_ID
WHERE e.division = 'HR'
  AND b.bonus >= 5000;

Full explanation →

Tips for test day

  • Read the output format twice. Check which columns it wants, in what order, and whether it asks for sorting. An extra column or a missing ORDER BY fails the hidden tests even when the logic is right.
  • Turn the words into operators slowly. “Less than”, “more than” and “or more” each map to one operator. Most wrong answers to this test are a > that should be >= or the other way round.
  • Run the query before you submit. The sample data in the editor is small. Passing it doesn’t mean you’ll pass the hidden tests.
  • Test with your own rows. Before the test, set up the tables from the solution pages in MySQL or SQLite and add awkward rows: a value exactly on the limit, a NULL, a row with no match in the other table. Each solution page lists the rows I used and the output I got.
  • Watch the clock. 30 minutes for two queries is plenty if you know the patterns. Don’t spend 20 minutes on the first one.

FAQ

Is the HackerRank SQL (Basic) certification free?

Yes. HackerRank’s help centre describes its certifications as free, timed assessments.

What if I fail?

You can take it again. HackerRank’s community help centre says you can retake a certification test 30 days after your previous attempt. Its FAQ also says failed attempts stay private and are not shared with companies.

Are these the actual questions?

The five question names and table layouts match my 2022 repo and many repos other people have shared since, including some from 2025. The wording on this site is mine. HackerRank can change the pool at any time, so if you see a question that isn’t here, the same join-and-filter approach will usually get you through it.

Which database should I use for these answers?

MySQL. The other four queries are plain enough to run on most databases. Country Codes is the one to watch: SQL Server also lets you join strings with +, and Oracle uses ||, while in MySQL only CONCAT() works.