O'Reilly logo

Getting Started with SQL by Thomas Nield

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 5. WHERE

Over the next few chapters, we will be adding more functionalities to the SELECT statement. A very common task when working with data is filtering for records based on criteria, which can be done with a WHERE statement.

We will be learning more functions and using them in the WHERE clause, but we can also use them in SELECT statements, as discussed in the previous chapter. For the most part, expressions and functions can be used in any part of a SQL statement.

Filtering Records

We are going to open another database called weather_stations. Add this database to your database navigator (refer to Chapter 3 if you’ve forgotten how to do this). Double-click on the database and you will see there is a single table called STATION_DATA. This contains weather-related sample data gathered from various weather stations.

Execute a SELECT on all columns to see the data inside:

SELECT * FROM station_data;

There is a lot of data here: about 28,000 records (Figure 5-1). We are not going to glean a lot of interesting information by scrolling through these records one by one. We will need to learn some more SQL features to morph this data into something meaningful. We will start by learning the WHERE statement, which we can use to filter down records based on a criterion.

The weather_stations database
Figure 5-1. The weather_stations database
Note

Table names and columns can be defined in uppercase or lowercase. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required