<jupyter_start><jupyter_text>FILTERING ROWS In SQL, the WHERE keyword allows you to filter based on both text and numeric values in a table. There are a few different comparison operators you can use:* = equal*  not equal* < less than*  > greater than * <= less than or equal to*  >= greater than or equal to   Simple filtering of numeric values Can be used for filtering both numbers and 'text'<jupyter_code>SELECT <column/s>
FROM <database>
WHERE <column> <operand> <value>;<jupyter_output><empty_output><jupyter_text>WHERE AND<jupyter_code>SELECT <column>
FROM <database>
WHERE <column> <operand> <value>
AND <column> <operand> <value>;

# Note that you need to specify the column name separately<jupyter_output><empty_output><jupyter_text>WHERE AND OR What if you want to select rows based on multiple conditions where some but not all of the conditions need to be met? For this, SQL has the OR operator.<jupyter_code>SELECT title
FROM films
WHERE release_year = 1994
OR release_year = 2000;
# When combining AND and OR, be sure to enclose the individual clauses in parentheses, like so:
SELECT title
FROM films
WHERE (release_year = 1994 OR release_year = 1995)
AND (certification = 'PG' OR certification = 'R');<jupyter_output><empty_output><jupyter_text>BETWEEN In SQL the BETWEEN keyword provides a useful shorthand for filtering values within a specified range.<jupyter_code>SELECT title
FROM films
WHERE release_year
BETWEEN 1994 AND 2000;<jupyter_output><empty_output><jupyter_text>Similar to the WHERE clause, the BETWEEN clause can be used with multiple AND and OR operators, so you can build up your queries and make them even more powerful!<jupyter_code>SELECT name
FROM kids
WHERE age BETWEEN 2 AND 12
AND nationality = 'USA';<jupyter_output><empty_output><jupyter_text>WHERE IN The IN operator allows you to specify multiple values in a WHERE clause, making it easier and quicker to specify multiple OR conditions!<jupyter_code># Instead of using this
SELECT name
FROM kids
WHERE age = 2
OR age = 4
OR age = 6
OR age = 8
OR age = 10;

# USE THIS!
SELECT name
FROM kids
WHERE age IN (2, 4, 6, 8, 10);<jupyter_output><empty_output><jupyter_text>LIKE and NOT LIKE As you've seen, the WHERE clause can be used to filter text data. However, so far you've only been able to filter by specifying the exact text you're interested in. In the real world, often you'll want to search for a pattern rather than a specific text string.In SQL, the LIKE operator can be used in a WHERE clause to search for a pattern in a column. To accomplish this, you use something called a wildcard as a placeholder for some other values. There are two wildcards you can use with LIKE:The % wildcard will match zero, one, or many characters in text. For example, the following query matches companies like 'Data', 'DataC' 'DataCamp', 'DataMind', and so on:<jupyter_code>SELECT name
FROM companies
WHERE name LIKE 'Data%';<jupyter_output><empty_output><jupyter_text>The _ wildcard will match a single character. For example, the following query matches companies like 'DataCamp', 'DataComp', and so on:<jupyter_code>SELECT name
FROM companies
WHERE name LIKE 'DataC_mp';<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06649937264742785, 'fraction_numerical': 0.012233375156838143, 'mean_word_length': 5.575257731958763, 'pattern_counts': {'":': 0, '<': 48, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '532722', 'license': 'MIT', 'n_tokens_mistral': 976, 'n_tokens_neox': 897, 'n_words': 444, 'path': 'FILTERING ROWS.ipynb', 'repo_name': 'robibanadera/SQL_Cheatsheet', 'size': '3188'}