Skip to Content
Getting Started with SQL
book

Getting Started with SQL

by Thomas Nield
February 2016
Beginner content levelBeginner
131 pages
2h 38m
English
O'Reilly Media, Inc.
Book available
Content preview from Getting Started with SQL

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. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Head First SQL

Head First SQL

Lynn Beighley
SQL Fundamentals

SQL Fundamentals

Thomas Nield
Learning SQL

Learning SQL

Ben Forta

Publisher Resources

ISBN: 9781491938607Errata Page