562 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owls only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Using Criteria in SQL Queries
Part two of a six-part series of blogs
When you write queries in SQL it's immensely useful to be able to show records matching criteria that you've set. You can do this using the WHERE clause and this blog teaches you how to use it!
Numbers are perhaps the easiest type of data for which to write criteria, which is why we're using them as a starting point.
You can use a range of different symbols, known as operators, for comparing numbers: the table below shows you the main ones you're likely to use:
|Operator||Alternative||What it means|
|<>||!=||Not equal to|
|>=||!<||Greater than or equal to (or not less than)|
|<=||!>||Less than or equal to (or not greater than)|
The operator always sits between the two values you are comparing. For example, the query below compares the value of the FilmRunTimeMinutes field with the value 180:
FilmRunTimeMinutes >= 180
The query shows all of the films whose running time is greater than or equal to 180:
The shortest film in this list is 180 minutes long.
You can use the BETWEEN keyword to find numbers that fall between an upper and lower limit. The example below would find all of the films whose running time is between 90 and 100 minutes.
FilmRunTimeMinutes BETWEEN 90 AND 100
A selection of the results from this query are shown below:
You can see from the diagram that films lasting exactly 90 and 100 minutes are included in the results of the query.
You can use the IN keyword to find records that match any values in a list of numbers. The example below looks for films whose running time is exactly 100, 150 or 200 minutes:
FilmRunTimeMinutes IN (100,150,200)
Note that the list of numbers must be enclosed in a set of parentheses. The results of this query are shown in the diagram below:
There aren't any films with a running time of exactly 200 minutes.
Now that you've seen how easy it is to write criteria using numbers it's time to see a few of the quirks of writing criteria involving text.
|Parts of this blog|
25 Aytoun Street