'Google Sheets query with multiple criteria not giving the desired results

I have a Google spreadsheet where I'm trying to pull data from two tabs if certain criteria is met. I want the query to return the values from the first column if the 10th column has no data, and the 8th column is either blank or has a value of 5 or less. What is happening is that it is returning values where the 8th column is less than 5, but the 10th column isn't blank. This is the formula I'm using:

=QUERY({'sheet1'!A2:J; 'sheet2'!A2:J}, "select Col1 where Col10='' and Col8 is null or Col8 <=5")

The 10th column is a text value, whereas the 8th one is a number. I've tried using a query within a query, but that just gave me errors.



Solution 1:[1]

try:

=QUERY({'sheet1'!A2:J; 'sheet2'!A2:J}, 
 "select Col1 
  where Col10 is null 
    and (Col8 is null 
     or  Col8 <=5)", 0)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 player0