Get startedGet started for free

Syntax order - New Zealand earthquakes

When executing a query, the processing order of the main SQL syntax is different from the written order in the query.

You want a simple query that returns all the recorded earthquakes in New Zealand that had a magnitude of 7.5 or higher. You think the query out in a sentence before creating it.

From the Earthquakes table, filter for only rows where Country equals 'NZ' and Magnitude greater than or equal to 7.5. Then, select the columns Date, Place, NearestPop, and Magnitude. Order the final results from the largest Magnitude to the smallest Magnitude.

The sample code is arranged in the order that matches the above sentence, which is the same as the SQL syntax processing order in the database. You will need to reorder it so that it runs without error.

This exercise is part of the course

Improving Query Performance in SQL Server

View Course

Exercise instructions

  • Complete the required query using FROM, WHERE, SELECT and ORDER BY.
  • Rearrange the query so that the syntax is in the order that it will run without error.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

/*
Returns earthquakes in New Zealand with a magnitude of 7.5 or more
*/

___ Earthquakes
___ Country = 'NZ'
___ Date, Place, NearestPop, Magnitude
	AND Magnitude >= 7.5
___ ___ Magnitude DESC;
Edit and Run Code