SQL Flow Field Guide

Combine filters with AND and OR

Use parentheses to make a multi-part row filter clear.

What you are trying to do

A support lead wants tickets with priority 2 or higher that are open or marked urgent.

Work through it

  1. Read the priority test and the parenthesized status choices.
  2. Apply the OR condition inside the parentheses.
  3. Keep a row only when the priority test and the grouped condition are both TRUE.

Check your work

Tickets 1 and 3 remain. Ticket 2 fails the priority test, and ticket 4 is neither open nor urgent.

Practice SQL

Open in SQL Flow
SELECT TicketId, Priority
FROM (VALUES (1, 2, N'Open', 0), (2, 1, N'Open', 0), (3, 3, N'Closed', 1), (4, 3, N'Closed', 0)) AS Ticket(TicketId, Priority, State, IsUrgent)
WHERE Priority >= 2 AND (State = N'Open' OR IsUrgent = 1)
ORDER BY TicketId;

Knowledge check

Commands in this lesson

Next lesson Choose whether duplicate values stay