All examples

Examples

Tracing an SQL query, clause by clause

FROM, WHERE, ORDER BY and SELECT applied in the order SQL runs them, on a small table of students’ marks.

  • 0:55
  • Code problems
  • Narrated by Erinome
  • English

Made from a prompt

Trace this on students(name, marks) with Asha 92, Ravi 78, Meera 85: SELECT name FROM students WHERE marks > 80 ORDER BY marks DESC;

Video transcript

In this video, we trace an SQL query that filters and sorts student records.

Question one: SQL tracing. Trace this on students, name and marks, with Asha ninety-two, Ravi seventy-eight, Meera eighty-five.

FROM students reads the three rows. WHERE marks greater than eighty keeps only rows whose marks exceed eighty. Asha has ninety-two marks, so Asha stays.

Ravi has seventy-eight marks, so Ravi is excluded. Meera has eighty-five marks, so Meera stays. ORDER BY marks DESC sorts the remaining rows by marks, highest first.

Ninety-two comes before eighty-five, so Asha comes before Meera. SELECT name returns only the names, not the marks. Notice that sorting by marks does not require displaying marks.

Hence, the output is Asha followed by Meera.

Your topic, drawn in about a minute.

Your first 2 videos are free, up to 1 minute each, watermarked. No card required. Full product, every voice and style included.