Skip to Content
Getting Started with SQL
book

Getting Started with SQL

by Thomas Nield
February 2016
Beginner
131 pages
2h 38m
English
O'Reilly Media, Inc.
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.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Head First SQL

Head First SQL

Lynn Beighley
SQL Fundamentals

SQL Fundamentals

Thomas Nield

Publisher Resources

ISBN: 9781491938607Errata Page