**SQL Filter Query**

In SQL you can set up criteria to query only the specific rows that interest you the most. The WHERE clause is used in SQL filter queries to apply the conditions in SELECT, INSERT, UPDATE, or DELETE sentences.

For the scope of this post, **we’ll describe how to use comparison, special, and Boolean operators with the WHERE clause**. You’ll also learn how to build subqueries and a CASE WHEN expression using WHEN.

We’ll show the examples using the FIFA players 2018 dataset that contains all the statistics and playing attributes of all the players in the full version of FIFA 18.

**Note:** This article covers basic SQL filter queries and is dedicated to SQL beginners. For the sake of simplicity, we took only the first 200 rows from the dataset. The example queries work well with Amazon Redshift, but some of them may conflict with other SQL databases.

**Comparison Operators**

In the WHERE clause, you can use the following operators, which are called relational, since they compare the values of two operands:

= | Equal. A column or expression matches a value. |

<> | Not equal. Use when you need to exclude a value. |

> | Greater than |

< | Less than |

>= | Greater than or equal |

<= | Less than or equal |

**Note:**

• In some versions of SQL the inequality operator may be written as !=.

• All uppercase characters are less than all lowercase characters, so ‘Z’ < ’a’, but ‘a’ < ‘z’. Also, all numbers are less than all characters, so ‘1’ < ‘Z’.

`SELECT name, age FROM fifa_dataset WHERE club = ‘Real Madrid CF’;`

*Powered by Statsbot*

**Note:** Text fields in SQL require ‘single quotes’, while numeric fields don’t.

**Boolean expressions**

These expressions test for the truth of some condition. To filter query results in SQL, you can use **AND, OR, and NOT**.

AND. TRUE if all of a set of comparisons are TRUE.

OR. TRUE if either of a set of comparisons is TRUE.

NOT. Reverses the value of any other Boolean operator.

`SELECT name FROM fifa_dataset WHERE club = ‘Real Madrid CF’ AND strength >= 80;`

*Powered by Statsbot*

Boolean expressions seem to be simple unless you combine them in a complex SQL filter query. You can effectively manage Boolean and relational expressions using parentheses, which determine the order of operations. When you see a long WHERE clause with Boolean expressions, to keep things simple you need to estimate the value of internal operators and then apply the upper external operator.

Keep doing this until the expressions end. ;)

`SELECT name, club FROM fifa_dataset WHERE NOT((age >= 30 AND balance < 70) OR potential < 90);`