$ settings --editor

$ settings --general

$ save --settings

SQL for beginners

Comparison operators #

The condition in a WHERE clause is usually built with a comparison operator. SQL supports the following:

Operator Meaning
= equal to
<> or != not equal to
< less than
> greater than
<= less than or equal to
>= greater than or equal to

Example #

SELECT
    *
FROM
    products
WHERE
    price > 30;

Result:

+----+-------------------+-------------+-------+
| id |       name        |  category   | price |
+----+-------------------+-------------+-------+
| 2  | Bluetooth Speaker  | Electronics | 45.5  |
| 4  |   Running Shoes    |   Fitness   |  60.0 |
| 8  |      Backpack      |   Office    |  40.0 |
+----+-------------------+-------------+-------+

Only the products with a price greater than 30 are kept. You can use any of the comparison operators above the same way, for example:

SELECT
    *
FROM
    products
WHERE
    category <> 'Office';

keeps every row whose category is not 'Office'.


Exercise #

Write a query that retrieves all columns from the products table, keeping only the rows where price is greater than 30.

  • The result has a price column.
  • The result contains exactly the rows where price is greater than 30, and no others.
Solution
SELECT
    *
FROM
    products
WHERE
    price > 30;
Output will be displayed here