Filtering by Multiple Conditions

We wish to filter rows that satisfy a logical combination of multiple conditions.

We will cover the two most common scenarios:

  • Taking the AND (conjunction) of two (or more) logical expressions.
  • Taking the OR (disjunction) of two (or more) logical expressions.

AND

We wish to filter rows that meet two (or more) conditions.

In this example, we wish to filter rows of the table table_1 where the numeric column col_6 is greater than 0 and where the string column col_8 has a value that equals ‘YES’.

SELECT *
FROM refcon.dataset.table_1
WHERE col_6 > 0
  AND col_8 = 'YES';

Here is how this works:

  • To filter rows that satisfy more than one condition, we use the AND operator.
  • Any row satisfying all the conditions will be retained (included in the output).

OR

We wish to filter rows that meet any one of two (or more) conditions.

In this example, we wish to filter rows of the table table_1 where the numeric column col_6 is greater than 0 or where the string column col_8 has a value that equals ‘YES’.

SELECT *
FROM refcon.dataset.table_1
WHERE col_6 > 0
  OR col_8 = 'YES'

Here is how this works:

  • To filter rows that satisfy one of two or more conditions, we use the OR operator.
  • Any row satisfying any one of the conditions will be retained (included in the output).
SQL
I/O