Query CONTAINS Google Sheets

Each column of data can only hold boolean, numeric (including date/time types) or string values.

  • In case of mixed data types in a single column, the majority data type determines the data type of the column for query purposes. Minority data types are considered null values.

  • query - The query to perform, written in the Google Visualization API Query Language.

    • The value for query must either be enclosed in quotation marks or be a reference to a cell containing the appropriate text.

    • See https://developers.google.com/chart/interactive/docs/querylanguage for further details on the query language.

  • headers - [ OPTIONAL ] - The number of header rows at the top of data. If omitted or set to -1, the value is guessed based on the content of data.

  • Examples

    Make a copy

    Note: Each example is in its own tab.

    Sample data

     

    Select & where

    Returns rows that match the specified condition using QUERY(A2:E6,F2,FALSE)1 and QUERY(A2:E6,F2,FALSE)2 clauses.

     

    Group by

    Aggregates QUERY(A2:E6,F2,FALSE)3 values across rows using QUERY(A2:E6,F2,FALSE)1 and QUERY(A2:E6,F2,FALSE)5 clauses.

     

    Pivot

    Transforms distinct values in columns into new columns.

     

    Order by

    Aggregates QUERY(A2:E6,F2,FALSE)6 values across rows and sorts by the maximum value of QUERY(A2:E6,F2,FALSE)3.

     

    Headers

    Specifies the number of header rows in the input range, which enables transformation of multi-header rows range input to be transformed to a single row header input.

    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:

    Query CONTAINS Google Sheets

    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‘ or the string ‘Mav‘:

    In this tutorial, you will learn how to select rows that contain strings using a Google Sheets Query.

    How To Select Rows that Contain String (Google Sheets Query)

    Quick Navigation

    In Google Sheets, the Query function is the most powerful and adaptive feature in the application. It’s a versatile and powerful tool that allows you to manipulate data in Google Sheets using data commands. This single-function replaces a slew of others and can replicate the majority of pivot table functionality.

    A text string usually referred to as a string or just text, is a collection of characters used as data in spreadsheet software. Words make up the majority of text strings, although they can also include letters, numbers, special characters, the dash symbol, and the number sign.

    Once you’re ready, we’ll get started by utilizing real-world examples to show you how to select rows that contain strings using Google Sheets Query.

    Understand Google Sheets Query

    Before using an example, you will need to understand how does a Google Sheets query work.

    =QUERY(data, query, [headers])

    Google Sheets query requires 3 arguments:

    1. the data range you want to look at
    2. the query you want to run, in quotation marks
    3. an optional number indicating the number of header rows in your data

    Select Rows that Contain Strings using Google Sheets Query

    Before we begin we will need a group of data to be used for the Google Sheets query formula.

    Step 1

    Know what string we want to select from the entire data range. In this example, we want to select only the rows containing the word Burger.

    Step 2

    To begin the query formula, we select an empty cell to input the formula. In this example, it will be K1. Then, we will insert an equal symbol followed by ‘QUERY’ and an open bracket. There will be a blue question mark at the side, you can click on it to reveal the arguments needed for this function to work.

    Query CONTAINS Google Sheets

    Step 3

    Next, we insert our argument. We will select A1: I51 as our data range, which is our first argument. Then, we will insert “SELECT B, C where C contains ‘BURGER’”, which is our second argument. Always remember to close any formulas with a closing bracket to signify that the formula is now complete.

    Query CONTAINS Google Sheets

    Step 4

    Once you press Enter, the rows containing the string ‘Burger’ from column C will appear. It will look something like this.

    Query CONTAINS Google Sheets

    Take Note!

    1. Google Sheets Query is sensitive to upper and lower case, hence if you typed ‘Burger’ instead of ‘BURGER’, the function will return no data containing this string.
    2. The data returned from the Query function will not be formulated. You can edit the data to your own preferences.

    Summary

    That’s all there is to it. You are welcome to copy the example spreadsheet below to see how it is done. The most crucial lesson is to enjoy yourself while doing it.

    Example Spreadsheet: 

    In this tutorial, I covered how to make categories in google sheets. Want more? Check out all the Google Sheets Tutorials.

    Is there a Contains function in Google Sheets?

    Is There an IF Contains Function in Google Sheets? There isn't a specific IF CONTAINS function in Google Sheets. However, you can cleverly combine the IF and the SEARCH or REGEXMATCH function to find whether a cell contains a particular value.

    How do you find contains in Google Sheets?

    Check If Cell Contains Specific Text in Google Sheets Using IF+SEARCH.
    Step 1: Identify the string and where to search. ‍ ... .
    Step 2: Add the function =IFERROR(IF(SEARCH(string, range), value_if_true), value_if_false) ‍ ... .
    Step 3: Check output. ‍.

    How do you check if a cell contains a value in Google Sheets?

    ISBLANK returns TRUE if value is empty or a reference to an empty cell, and FALSE if it contains data or a reference to data.

    How do I select rows containing specific text in Google Sheets?

    Show Rows That Contain Specific Text in Google Sheets Click on the filter button next to Product (cell B2) and go to Filter by condition. In the drop-down list, choose Text contains.