Using !, =, <, > to filter data in SQL
Want to try your newly developed SQL skills?Start with Weld
The example above used a very simple = to indicate the condition to be fulfilled in the WHERE statement. Some of the most used simple ways to indicate the conditions are:
- = Equal to
- != Not equal to
- > Greater than
- < Less than
These work the same way as in Excel and are simple, especially for numerical values.
Exercise 2: Find all items where the price is higher than 97
For this exercise, you’ll look at the prices of what’s being ordered in the sample e-commerce data. This is located in a table you have not used before called webshop_order_line. You can find it grouped together with the other tables you’ve worked with in the sidebar to the left.
Try to find all the columns in the table, but select only the rows where the price value is higher than 97. If you run your query, it should give a result like this:
In SQL there are often many means to an end, so you’ll usually be able to get the required result by writing different variations of the same query. A simple way to solve the exercise above would be to write a query like this:
3 , order_id
4 , product
5 , quantity
6 , price
10 price > 97
Remember that the formatting of your query is completely up to you, so whether you write the commas to separate the columns you select on the same line as the column names, or the one above, is only depending on your style.