Helix Systems' leadership is reviewing the hiring pipeline and wants to see recent additions to the team first.
Write a query to return each employee's name and hire date, ordered from most recently hired to earliest.
Assumptions:
- The
employeestable contains every active and former employee at Helix Systems. - When two employees share a
hire_date, the employee with the loweridshould appear first.
Output:
- One row per employee, with columns
nameandhire_date, sorted byhire_datedescending, then byidascending.
Schema · hr 4 tables
Run previews · Check grades
Write a query, then run it to see results here.
Worked solution Try it yourself first
SELECT
name,
hire_date
FROM
employees
ORDER BY
hire_date DESC,
id The shape
DESC on the date column flips the sort so the most recent hire lands on top, and an ascending id tiebreaker keeps employees hired on the same day in a predictable order.
Clause by clause
SELECT name, hire_datepulls the two columns leadership wants to see: who joined and when.FROM employeesreads the full employee table — every active and former employee, since the pipeline review wants the complete history.ORDER BY hire_date DESC, idsorts byhire_datedescending so newest hires come first, then breaks ties byidascending. Each sort key carries its own direction;DESCapplies only tohire_date, andidfalls back to the default ascending.
Why this and not ORDER BY hire_date DESC, id DESC
The direction on the tiebreaker is a choice, not an obligation. Either direction produces a deterministic order, so either is correct in the strict sense. Ascending id is the convention because IDs usually grow over time — employees hired earlier in the same day tend to have lower IDs — so an ascending tiebreaker mirrors the order in which the records were actually created. It's the kind of detail that doesn't matter for a single query but starts to matter once the result has to look consistent across many reports.
You practiced sorting a date column descending to put the newest records on top. DESC reverses the default ordering for any sortable type — the recurring shape behind every recency-first feed, leaderboard, or audit report.