The example above used a very simple <span class="code">=</span> to indicate the condition to be fulfilled in the <span class="code">WHERE</span> statement. Some of the most used simple ways to indicate the conditions are:
- <span class="code">=</span> Equal to
- <span class="code">!=</span> Not equal to
- <span class="code">></span> Greater than
- <span class="code"><</span> 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 <span class="code">webshop_order_line</span>. 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:
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.