Courseiva
Using Spark SQL →easyMultiple Choice

Databricks-Spark-Assoc Using Spark SQL Practice Question

A data analyst needs to run a Spark SQL query that returns the top 5 highest-paid employees from a table named employees, ordered by salary descending. Which query correctly returns exactly five rows?

⚠ Common exam trap

The trap here is assuming that other SQL dialects' TOP or FETCH FIRST syntax works in Spark SQL, or that LIMIT can precede ORDER BY.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

SELECT * FROM employees ORDER BY salary DESC LIMIT 5

To get the top 5 highest-paid employees, the query must sort by salary descending and then apply LIMIT 5. Spark SQL supports ORDER BY followed by LIMIT, which returns the first five rows after sorting, exactly matching the requirement.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    SELECT TOP 5 * FROM employees ORDER BY salary DESC

    Why it's wrong here

    Spark SQL does not support the TOP keyword, which is specific to other database systems like SQL Server. Using TOP will result in a parse error. Spark SQL uses the LIMIT clause to restrict the number of rows returned, so this query is invalid for Spark.

  • ✓

    SELECT * FROM employees ORDER BY salary DESC LIMIT 5

    Why this is correct

    This query sorts all employees by salary in descending order and then limits the result to the first five rows. In Spark SQL, LIMIT after ORDER BY returns the top N rows according to the sort, which exactly matches the requirement to get the five highest-paid employees.

  • ✗

    SELECT * FROM employees ORDER BY salary DESC FETCH FIRST 5 ROWS ONLY

    Why it's wrong here

    The FETCH FIRST syntax is standard SQL and supported by some databases, but Spark SQL does not implement it. Spark SQL uses LIMIT instead. This query would fail with a syntax error, so it cannot return the desired top 5 employees.

  • ✗

    SELECT * FROM employees LIMIT 5 ORDER BY salary DESC

    Why it's wrong here

    In Spark SQL, the ORDER BY clause must appear before LIMIT. Placing LIMIT before ORDER BY causes a syntax error or unexpected behavior, and even if accepted, it would limit rows before sorting, not return the top 5 by salary. The correct order is ORDER BY then LIMIT.

About these practice questions

This Databricks-Spark-Assoc question is part of Courseiva's 295-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official Databricks exam blueprint

This Databricks-Spark-Assoc practice question is part of Courseiva's free Databricks certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the Databricks-Spark-Assoc exam.