SQL Flow Field Guide

Order a short result

Use a stable order before limiting rows.

What you are trying to do

A support screen shows the three highest-priority synthetic tickets.

Work through it

  1. Read both ORDER BY keys.
  2. Check how the ticket ID breaks priority ties.
  3. Change the row values and predict which three rows remain.

Check your work

The same input produces the same three rows in the same order.

Practice SQL

Open in SQL Flow
SELECT TOP (3) TicketId, Priority FROM (VALUES (104, 1), (102, 1), (107, 2), (101, 1), (103, 3)) AS Ticket(TicketId, Priority) ORDER BY Priority, TicketId;

Commands in this lesson

Next lesson Join related rows