How to select Rows that Contain String using Query function
To select rows that contain a specific string using the QUERY function in Google Sheets, follow these steps:
- Identify the range of data you want to query. For example, if your data is in columns A to D and rows 1 to 100, your range would be A1:D100.
- Determine the string you want to search for. For example, let's say you want to select rows that contain the word "apple".
- Use the QUERY function with the CONTAINS operator to filter the rows based on the string. The syntax for the QUERY function is:
QUERY(data, query, [headers])
.
Here's an example to demonstrate how to select rows that contain the string "apple" from a range of data in columns A to D and rows 1 to 100.
Example
Assuming your data is in the range A1:D100, and you want to select rows that contain the word "apple", you can use the following formula:
=QUERY(A1:D100, "SELECT * WHERE A CONTAINS 'apple' OR B CONTAINS 'apple' OR C CONTAINS 'apple' OR D CONTAINS 'apple'")
In this formula:
A1:D100
is the data range you want to query.SELECT *
is used to select all columns in the data range.WHERE A CONTAINS 'apple' OR B CONTAINS 'apple' OR C CONTAINS 'apple' OR D CONTAINS 'apple'
is the condition to filter rows based on the presence of the word "apple" in columns A, B, C, or D.
This formula will return a new table with the rows that contain the word "apple" in any of the columns from A to D.
Did you find this useful?