One way to restrict the data presented from a query is to use a
WHERE is used to return data that matches a specified condition and is combined with the comparison operators
Let’s say we wanted to know all the months where more than 1,000 of one type of animal was taken in. We could run a query like this one:
SELECT year, month, animal_type, count FROM austin_animal_center_intakes_by_month WHERE COUNT > 1000
and we would get these results:
You can also use a
!= to limit results for text fields. E.g., if we wanted only to look at information about cats taken in by the Austin Animal Center we could run this query:
SELECT year, month, count, animal_type FROM austin_animal_center_intakes_by_month WHERE animal_type = "Cat"
The first seven rows returned would look like this:
<=against columns which contain strings of text, the results might not be what you expect. Text strings are treated like numbers with alphabetic order determining which is greater than and which is less than. If we were to run a query against the Intakes table for all animal types
>“Cat” the results would include all Dogs, Livestock, Other, and Wildlife, but no cats or birds.
An introduction to the
ORDER BY clause.