559 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 one 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!
This blog teaches you how to add criteria to your SQL queries to find specific records in a table. You'll learn about how to work with text, dates and numbers in the WHERE clause of a query.
If you've read our blog on basic SQL queries you'll remember that the WHERE clause is the third of six keywords in a basic query. If you didn't read that blog or you just need a reminder here's where it fits in:
The most basic criteria you can write in SQL queries involve comparing the value of a field against another value that you provide. In the example below we're comparing the value of the FilmRunTimeMinutes field with the value 120 and asking if they are equal to each other:
FilmRunTimeMinutes = 120
When this query is executed we'll return all of the films whose running time is equal to the number we have provided:
These films all last for 120 minutes.
You might sometimes see people writing their criteria contained within parentheses, as shown below:
(FilmRunTimeMinutes = 120)
With such a simple query the brackets make no difference to the results and so you can happily leave them out.
For more complex combinations of criteria you may find brackets helpful to clarify your query for other readers. A later part of this blog series shows an example where using brackets is essential for SQL Server to understand what you're trying to do!
Now that you know the basics of where the WHERE clause fits and what it's for, it's time to look in more detail at criteria involving specific data types; starting with numbers.
|Parts of this blog|
25 Aytoun Street