> For the complete documentation index, see [llms.txt](https://cybersecurity-cloud-and-it-notes.gitbook.io/kyles-cybersecurity-cloud-and-it-gitbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cybersecurity-cloud-and-it-notes.gitbook.io/kyles-cybersecurity-cloud-and-it-gitbook/google-cybersecurity-professional-cert/4.-linux-and-sql-tool-of-the-trade/module-4/sql-queries/basic-filters-on-sql-queries.md).

# Basic Filters on SQL Queries

Here’s a fun and ADHD-friendly breakdown of **SQL Filtering**!

***

#### **🍎 Filtering in SQL: Picking the Best Apples!**

Think of filtering in SQL like picking apples from a fruit cart—you only want the **freshest** apples, right? Filtering lets you **choose exactly** what you want from your data. Let’s dive into how SQL does it!

***

#### **🔍 What is Filtering?**

**Filtering** = Only grabbing the **data** that meets a specific **condition**.

* **Example:** You’re looking through login attempts from different countries and you only want to see the ones from **Canada**. Filtering will give you just that!

***

#### **⚙️ Operators: The SQL Magic Symbols!**

An **operator** is like the **symbol** or **word** that makes the magic happen!

* **= (Equal to):** Only grabs data that is **exactly** equal to something.
  * Example: `country = 'USA'` → Grabs all login attempts from the **USA**.

***

#### **🧠 WHERE: The Key to Filtering!**

The keyword **WHERE** is your tool for applying filters.

Here’s how you write a filter in SQL:

1. **SELECT** the columns you want.
2. Use **FROM** to choose the table.
3. **WHERE** sets the condition for your filter.

* **Example:** To find login attempts from the **USA**, your query would look like this:

```
SELECT *
FROM log_in_attempts
WHERE country = 'USA';
```

This will show only the rows where the login came from the USA!

***

#### **🔗 Wildcards: When You Need to Be Less Specific!**

Sometimes you don’t want an **exact match**—maybe you want all offices that **start with East**, like **East-120** or **East-290**. For this, SQL uses a **wildcard**.

* Use `%` as a **wildcard** to fill in any characters you’re unsure about.

  * **Example:** To find all offices that start with **East**, use:

  ```
  SELECT *
  FROM employees
  WHERE office LIKE 'East%';
  ```

  This will return **East-120**, **East-290**, and anything else that starts with "East"!

***

#### **🔁 LIKE: The Operator for Patterns!**

When searching for patterns, you can’t use `=`—instead, you use **LIKE**.

* **LIKE** is used with **WHERE** to find patterns.

  * Example: To grab all country names that start with **US**, whether it’s **US** or **USA**:

  ```
  SELECT *
  FROM log_in_attempts
  WHERE country LIKE 'US%';
  ```

This will return both **US** and **USA** entries!

***

#### **🎯 Key Takeaways: You’re a Filtering Pro!**

* **Filtering**: Grab only the data you need.
* **Operators**: `=` for exact matches, **LIKE** for patterns.
* **WHERE**: The magic word for applying filters.
* **Wildcards**: `%` helps match patterns when things aren’t exact.

***

Wow, you’re already super precise with your data! 🎉 Keep practicing, and you’ll be a SQL filtering wizard in no time. Ready for what’s next? 🚀
