Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A community hall stores its events in a table Events. Dates are stored year first, so they sort in date order.
EventID Name EventDate Tickets
E1 Quiz night 2025-05-17 60
E2 Art fair 2025-07-02 150
E3 Fun run 2025-06-01 300
E4 Bake sale 2025-04-26 80
E5 Film club 2025-09-12 45
E6 Book swap 2025-06-21 35SELECT Name, EventDate
FROM Events
WHERE EventDate >= '2025-06-01'
ORDER BY EventDate ASC;ORDER BY field ASC sorts the output smallest first (A to Z, earliest date first); DESC sorts largest first. The clauses come in the order SELECT, FROM, WHERE, ORDER BY. Keep the records that pass, sort them, then show the selected fields.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Step 1. Keep the dates on or after 1 June. Art fair (2 July), Fun run (1 June), Film club (12 September) and Book swap (21 June). Quiz night (17 May) and Bake sale (26 April) are earlier, so they are left out.
Step 2. Sort the four dates, earliest first.
SELECT Name, EventDate
FROM Events
WHERE EventDate >= '2025-06-01'
ORDER BY EventDate ASC;The output:
Name EventDate
Fun run 2025-06-01
Book swap 2025-06-21
Art fair 2025-07-02
Film club 2025-09-12Step 3. The Fun run. Its date is exactly 1 June. The operator is >=, so a date equal to the one in the condition passes. With > it would be left out.
Answer: (a) Fun run, Book swap, Art fair, Film club, with their dates. (b) rows. (c) The Fun run is first; it is in the output because >= includes 1 June itself.
Log in to join the discussion.
Loading…