How can I use Google Sheets Query to select rows that contain a specific string?

Google Sheets Query is a powerful tool that allows users to manipulate and analyze data in their spreadsheets. One useful feature of Query is the ability to select rows that contain a specific string. This can be done by using the “contains” operator in the Query formula, followed by the desired string. The formula will then filter the data and only display rows that contain the specified string. This function is particularly useful for organizing and categorizing data, as it allows users to easily locate and analyze information related to a specific term or keyword. Using the Google Sheets Query feature to select rows that contain a specific string can greatly enhance data management and analysis capabilities.

Google Sheets Query: Select Rows that Contain String


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.

Additional Resources

x