---
title: Create a SQL Coding Challenge
description: Build and test a SQL query challenge in LeetLabs, with tables, sample rows and expected results.
---

[Skip to content](https://support.learnyst.com/create-a-sql-coding-challenge#main-content)

![Learnyst Logo-25-1.png\]](https://support.learnyst.com/hs-fs/hubfs/Learnyst%20Logo-25-1.png?height=40&name=Learnyst%20Logo-25-1.png)

- [Blogs](https://blog.learnyst.com/)
- [Product Demo](https://www.learnyst.com/product-demo)
- [Help Center](https://support.learnyst.com/?__hstc=63047858.c6632626f509e3bce8daa43b7e98f888.1712298652738.1721125968223.1721135407952.38&__hssc=63047858.1.1721135407952&__hsfp=1459259341&_gl=1*1hsz3xc*_gcl_aw*R0NMLjE3MzA4OTkxMzAuQ2p3S0NBaUF4S3k1QmhCYkVpd0FZaVctLTFMeml2UU9iS3JlNDdQaXE4Y2RDRTRPbE9iZnFVYS1sYkViTm5lcW52eHljMnNXOTRoMlRCb0N3QVVRQXZEX0J3RQ..*_gcl_au*MTM5MDI5MDc5LjE3MjU5Mzg3NTIuNjU1NTcwMzYxLjE3MzMyMzMxODAuMTczMzIzMzE3OQ..)
- [Success Stories](https://www.learnyst.com/customers/success-stories)

Open main navigation

Close main navigation

- [Blogs](https://blog.learnyst.com/)
- [Product Demo](https://www.learnyst.com/product-demo)
- [Help Center](https://support.learnyst.com/?__hstc=63047858.c6632626f509e3bce8daa43b7e98f888.1712298652738.1721125968223.1721135407952.38&__hssc=63047858.1.1721135407952&__hsfp=1459259341&_gl=1*1hsz3xc*_gcl_aw*R0NMLjE3MzA4OTkxMzAuQ2p3S0NBaUF4S3k1QmhCYkVpd0FZaVctLTFMeml2UU9iS3JlNDdQaXE4Y2RDRTRPbE9iZnFVYS1sYkViTm5lcW52eHljMnNXOTRoMlRCb0N3QVVRQXZEX0J3RQ..*_gcl_au*MTM5MDI5MDc5LjE3MjU5Mzg3NTIuNjU1NTcwMzYxLjE3MzMyMzMxODAuMTczMzIzMzE3OQ..)
- [Success Stories](https://www.learnyst.com/customers/success-stories)

 Hello, how can we help you today?

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

1. [Support Center](https://support.learnyst.com/?hsLang=en)
2. [Courses](https://support.learnyst.com/courses?hsLang=en)
3. [Add Lesson](https://support.learnyst.com/courses?hsLang=en#add-lesson)

# Create a SQL Coding Challenge

## Build and test a SQL query challenge in LeetLabs, with tables, sample rows and expected results.

SQL challenges let learners practise queries on tables you define. They're ideal for database, data analysis and backend courses. This guide walks through a complete SQL challenge that we built and tested on Learnyst. Read [Create a coding challenge](https://support.learnyst.com/create-a-coding-test?hsLang=en) first for the general steps.

**On this page**

- [How SQL challenges work](https://support.learnyst.com/create-a-sql-coding-challenge#how-sql-challenges-work)
- [Example: High earners](https://support.learnyst.com/create-a-sql-coding-challenge#example-high-earners)
- [Test it in Preview](https://support.learnyst.com/create-a-sql-coding-challenge#test-it-in-preview)
- [Tips for SQL challenges](https://support.learnyst.com/create-a-sql-coding-challenge#tips-for-sql-challenges)
- [Practice ideas for SQL](https://support.learnyst.com/create-a-sql-coding-challenge#practice-ideas-for-sql)

### How SQL challenges work

- **Schema & Seed Data** (in the **Problem Statement** step) creates the tables. Use `CREATE TABLE` statements here.
- Each test case **Input** adds the rows for that test, as `INSERT` statements.
- Each test case **Output** is the expected result of the learner's query.
- Learners write a `SELECT` query in the editor. The editor starts empty, with `-- Write your query here`.

**Write the expected output with a pipe (|) between columns**, one row per line, with no header row. For example: `Bob|70000`. The result panel shows the columns spaced out, but the comparison uses the pipe format. If you separate columns with tabs or spaces, even a correct query shows **Wrong Answer**.

Learners don't see your **Schema & Seed Data**. Describe every table and column in the problem statement, so learners know what to query.

### Example: High earners

**Problem Statement:**

```
High Earners
The employees table stores each employee's id, name, department and salary.
Write a query that returns the name and salary of every employee whose salary is greater than 50000.
Sort the result by salary, highest first.
Columns: id INTEGER, name TEXT, department TEXT, salary INTEGER
```

**Schema & Seed Data:**

```
CREATE TABLE employees (
  id INTEGER PRIMARY KEY,
  name TEXT,
  department TEXT,
  salary INTEGER
);
```

**Test Cases:**

| Title | Input | Output | Visibility |
| --- | --- | --- | --- |
| Three employees | `INSERT INTO employees VALUES (1,'Alice','HR',45000),(2,'Bob','IT',70000),(3,'Charlie','Finance',55000);` | `Bob\|70000` `Charlie\|55000` | Visible |
| One high earner | `INSERT INTO employees VALUES (1,'Dev','IT',90000),(2,'Ann','HR',30000);` | `Dev\|90000` | Hidden |

**Hints:** "Filter the rows: Use WHERE salary \> 50000 to keep only high earners." and "Sort the result: Use ORDER BY salary DESC to show the highest salary first."

**Solution:**

```
SELECT name, salary
FROM employees
WHERE salary > 50000
ORDER BY salary DESC;
```

### Test it in Preview

Click **Preview**, then **TAKE CHALLENGE**. The problem shows on the left, and the visible test case below the editor.

![SQL challenge in the learner coding screen](https://support.learnyst.com/hs-fs/hubfs/image-png-Dec-02-2026-12-37-30-4645-PM.png?width=670&height=377&name=image-png-Dec-02-2026-12-37-30-4645-PM.png)

A query without the filter returns every row, so **RUN** shows **Wrong Answer**, with your output next to the expected output.

![Wrong Answer for a query without the filter](https://support.learnyst.com/hs-fs/hubfs/image-png-Dec-02-2026-12-37-32-5239-PM.png?width=670&height=377&name=image-png-Dec-02-2026-12-37-32-5239-PM.png)

The correct query shows **Correct Answer**.

![Correct Answer for the correct query](https://support.learnyst.com/hs-fs/hubfs/image-png-Dec-02-2026-12-37-33-6588-PM.png?width=670&height=377&name=image-png-Dec-02-2026-12-37-33-6588-PM.png)

### Tips for SQL challenges

- Always add `ORDER BY` when the order matters, so the result rows come out in a predictable order.
- Keep each test case small: a few `INSERT` rows are enough to show the rule.
- Use a hidden test case where only some rows match, to catch queries that ignore the filter.

### Practice ideas for SQL

- Count employees in each department (GROUP BY)
- Find the highest salary per department
- Join orders with customers
- List customers with no orders (LEFT JOIN)
- Find duplicate email addresses

### What to do next

- [Create a coding challenge](https://support.learnyst.com/create-a-coding-test?hsLang=en): all the steps and options.
- [Publish and unpublish code challenges](https://support.learnyst.com/publish-and-unpublish-the-code?hsLang=en): make the challenge available for your courses.
- [Embed a coding challenge into courses](https://support.learnyst.com/embed-the-coding-challenge-into-courses?hsLang=en): add it as a lesson.

If you have questions, contact us at support@learnyst.com.

- [Get Started](https://support.learnyst.com/get-started#main-content)
- [AI Tools](https://support.learnyst.com/ai-tools#main-content)
- [Courses](https://support.learnyst.com/courses#main-content)

    - [Getting Started](https://support.learnyst.com/courses#getting-started)
    - [Build Course](https://support.learnyst.com/courses#build-course)
    - [Add Lesson](https://support.learnyst.com/courses#add-lesson)
    - [Course Settings](https://support.learnyst.com/courses#course-settings)
    - [Lesson Settings](https://support.learnyst.com/courses#lesson-settings)
    - [Course Certificate](https://support.learnyst.com/courses#course-certificate)
- [Mock test](https://support.learnyst.com/mock-test#main-content)

    - [Getting Started](https://support.learnyst.com/mock-test#getting-started)
    - [Build Mock Test](https://support.learnyst.com/mock-test#build-mock-test)
    - [GMAT Question Types](https://support.learnyst.com/mock-test#gmat-question-types)
    - [Mock test Settings](https://support.learnyst.com/mock-test#mock-test-settings)
    - [Mock Test Templates](https://support.learnyst.com/mock-test#mock-test-templates)
- [Test Series](https://support.learnyst.com/test-series#main-content)

    - [Getting Started](https://support.learnyst.com/test-series#getting-started)
    - [Build Test Series](https://support.learnyst.com/test-series#build-test-series)
    - [Settings](https://support.learnyst.com/test-series#settings)
    - [Test Series Templates](https://support.learnyst.com/test-series#test-series-templates)
- [Bundles](https://support.learnyst.com/bundles#main-content)

    - [Getting Started](https://support.learnyst.com/bundles#getting-started)
    - [Build Bundles](https://support.learnyst.com/bundles#build-bundles)
    - [Bundle Settings](https://support.learnyst.com/bundles#bundle-settings)
- [Batch](https://support.learnyst.com/batch#main-content)

    - [Batch Settings](https://support.learnyst.com/batch#batch-settings)
- [1:1 Coaching](https://support.learnyst.com/11-coaching#main-content)
- [Poll](https://support.learnyst.com/poll#main-content)
- [Track](https://support.learnyst.com/track#main-content)

    - [Getting Started](https://support.learnyst.com/track#getting-started)
    - [Track Settings](https://support.learnyst.com/track#track-settings)
- [Ebooks](https://support.learnyst.com/ebooks#main-content)
- [Podcasts](https://support.learnyst.com/podcasts#main-content)
- [Webinars](https://support.learnyst.com/webinars#main-content)
- [Digital/Custom Products](https://support.learnyst.com/digital-custom-products#main-content)
- [Free Resource](https://support.learnyst.com/free-resource#main-content)
- [Question Pool](https://support.learnyst.com/question-pool#main-content)

    - [Getting Started](https://support.learnyst.com/question-pool#getting-started)
    - [Build Question Pool](https://support.learnyst.com/question-pool#build-question-pool)
- [Quiz & Assessment](https://support.learnyst.com/quiz-assessment#main-content)

    - [Getting Started](https://support.learnyst.com/quiz-assessment#getting-started)
    - [Add Questions](https://support.learnyst.com/quiz-assessment#add-questions)
    - [Build Quiz](https://support.learnyst.com/quiz-assessment#build-quiz)
    - [Question Settings](https://support.learnyst.com/quiz-assessment#question-settings)
    - [Quiz Settings](https://support.learnyst.com/quiz-assessment#quiz-settings)
    - [Question Review Flow](https://support.learnyst.com/quiz-assessment#question-review-flow)
    - [Learner Results](https://support.learnyst.com/quiz-assessment#learner-results)
- [Classification](https://support.learnyst.com/classification#main-content)

    - [Categories](https://support.learnyst.com/classification#categories)
    - [Tags](https://support.learnyst.com/classification#tags)
- [Product Pricing](https://support.learnyst.com/product-pricing#main-content)

    - [Getting Started](https://support.learnyst.com/product-pricing#getting-started)
    - [Pricing Plans](https://support.learnyst.com/product-pricing#pricing-plans)
- [Website](https://support.learnyst.com/website#main-content)

    - [Getting Started](https://support.learnyst.com/website#getting-started)
    - [Building Website](https://support.learnyst.com/website#building-website)
    - [Website Navigation](https://support.learnyst.com/website#website-navigation)
    - [Superpower Widgets](https://support.learnyst.com/website#superpower-widgets)
    - [Sign Up Settings](https://support.learnyst.com/website#sign-up-settings)
    - [Widgets (Embeddables)](https://support.learnyst.com/website#widgets-embeddables)
- [Website Custom domain](https://support.learnyst.com/website-custom-domain#main-content)
- [Mobile Apps](https://support.learnyst.com/mobile-apps#main-content)

    - [Android](https://support.learnyst.com/mobile-apps#android)
    - [iOS](https://support.learnyst.com/mobile-apps#ios)
- [Communities](https://support.learnyst.com/communities#main-content)

    - [Learnyst Community](https://support.learnyst.com/communities#learnyst-community)
    - [Telegram Community](https://support.learnyst.com/communities#telegram-community)
- [Socials](https://support.learnyst.com/socials#main-content)
- [Gamification](https://support.learnyst.com/gamification#main-content)
- [Users](https://support.learnyst.com/users#main-content)

    - [Learners](https://support.learnyst.com/users#learners)
- [Learner Management](https://support.learnyst.com/learner-management#main-content)

    - [Learner Profile](https://support.learnyst.com/learner-management#learner-profile)
    - [Learner Actions](https://support.learnyst.com/learner-management#learner-actions)
    - [Learner Settings](https://support.learnyst.com/learner-management#learner-settings)
- [Zoho E-signin](https://support.learnyst.com/zoho-e-signin#main-content)
- [Roles and Permissions](https://support.learnyst.com/roles-and-permissions#main-content)
- [Marketing](https://support.learnyst.com/marketing#main-content)

    - [Refer Earn](https://support.learnyst.com/marketing#refer-earn)
    - [Push Message](https://support.learnyst.com/marketing#push-message)
    - [Marketing Email](https://support.learnyst.com/marketing#marketing-email)
    - [System Email](https://support.learnyst.com/marketing#system-email)
    - [Whatsapp Messenger](https://support.learnyst.com/marketing#whatsapp-messenger)
    - [Affiliates](https://support.learnyst.com/marketing#affiliates)
    - [Workflows](https://support.learnyst.com/marketing#workflows)
    - [Forms](https://support.learnyst.com/marketing#forms)
    - [Campaign](https://support.learnyst.com/marketing#campaign)
    - [CTA](https://support.learnyst.com/marketing#cta)
    - [Promo Slider](https://support.learnyst.com/marketing#promo-slider)
- [Workflows](https://support.learnyst.com/workflows#main-content)
- [Integrations](https://support.learnyst.com/integrations#main-content)

    - [Pabbly Integration](https://support.learnyst.com/integrations#pabbly-integration)
    - [Zapier Integration](https://support.learnyst.com/integrations#zapier-integration)
    - [Google Ads](https://support.learnyst.com/integrations#google-ads)
    - [Meta Ads](https://support.learnyst.com/integrations#meta-ads)
- [Newsfeed](https://support.learnyst.com/newsfeed#main-content)
- [Sales](https://support.learnyst.com/sales#main-content)
- [Ratings and Reviews](https://support.learnyst.com/ratings-and-reviews#main-content)
- [Learner Support](https://support.learnyst.com/learner-support#main-content)
- [Sub School](https://support.learnyst.com/sub-school#main-content)
- [Reports](https://support.learnyst.com/reports#main-content)

    - [Score Reports & Quiz Insights](https://support.learnyst.com/reports#score-reports-quiz-insights)
- [Content Security](https://support.learnyst.com/content-security#main-content)

    - [CourseGaurd](https://support.learnyst.com/content-security#coursegaurd)
- [School Settings](https://support.learnyst.com/school-settings#main-content)

    - [General Settings](https://support.learnyst.com/school-settings#general-settings)
    - [Learner Billing](https://support.learnyst.com/school-settings#learner-billing)
    - [Payment gateway](https://support.learnyst.com/school-settings#payment-gateway)
    - [Features](https://support.learnyst.com/school-settings#features)
    - [Security](https://support.learnyst.com/school-settings#security)
    - [Channels](https://support.learnyst.com/school-settings#channels)
- [Payments](https://support.learnyst.com/payments#main-content)

    - [Custom installments](https://support.learnyst.com/payments#custom-installments)
- [Subscriptions](https://support.learnyst.com/subscriptions#main-content)
- [Zoom integration](https://support.learnyst.com/zoom-integration#main-content)
- [Troubleshooting](https://support.learnyst.com/troubleshooting#main-content)

    - [Web – Windows](https://support.learnyst.com/troubleshooting#web-windows)
    - [Web – Mac](https://support.learnyst.com/troubleshooting#web-mac)
    - [Android app](https://support.learnyst.com/troubleshooting#android-app)
    - [General](https://support.learnyst.com/troubleshooting#general)
- [FAQs](https://support.learnyst.com/faqs#main-content)
- [Learners' Help article](https://support.learnyst.com/learners-help-article#main-content)
- [Add Ons](https://support.learnyst.com/add-ons#main-content)

- [Home](https://learnyst-1.hubspotpagebuilder.net/)
- [About Us](https://learnyst-1.hubspotpagebuilder.net/about-us)
- [Contact Us](https://learnyst-1.hubspotpagebuilder.net/contact-us)
- [Blog](https://learnyst.hs-sites-na2.com/blog)

[![Chill listening crop-3](https://support.learnyst.com/hs-fs/hubfs/Learnyst%20logo%20(2).png?width=24&height=24&name=Learnyst%20logo%20(2).png "Chill listening crop-3")](https://www.learnyst.com/)

Learnyst Support

Copyright © 2026, Learnyst Insights Pvt Ltd