How do I select rows that contain a string in Google Sheets Query?


You can use the following syntax to select rows that contain a specific string using the Google Sheets query function:

=query(A1:C9,select A, B where B contains ‘this’, 1)

This particular query selects columns A and B from the cell range A1:C9 where column B contains the string ‘this’ and the 1 specifies that there is 1 header row at the top of the cell range.

The following examples show how to use this function in practice with the following dataset:

Example 1: Select Rows that Contain a String

We can use the following syntax to select all rows where the Team column contains the string ‘Lak‘:

This query returns the two rows that contain the string ‘Lak’ in the Team column.

Example 2: Select Rows that Do Not Contain a String

We can use the following syntax to select all rows where the Team column does not contain the string ‘Lak‘:

Notice that this returns every row where the team name is not equal to Lakers.

Example 3: Select Rows that Contain One of Several Strings

We can use the following syntax to select all rows where the Team column contains the string ‘Lak‘ or the string ‘Mav‘:

This returns only the rows where the team name is equal to Lakers or Mavericks.

x