Search code examples
arraysgoogle-sheetsfiltergoogle-sheets-formulagoogle-query-language

Is there a Google sheets function that allow you to do multiple queries for different data sets with similar fields, but different conditions?


So I have a couple of Google Sheets tabs that contain similar data and want to merge into a master sheet, but have two different conditions for each query. I have tried:

={query({INVENTORY!$A:$Z},"SELECT Col1, Col2, Col3, Col4, Col5, Col15, Col17, Col18, Col7, Col11, Col12, Col13, Col14 WHERE Col15 IS NOT NULL and Col15 < "&F1&" and Col19 <> 'Printed' AND Col20 = 'Restock' ORDER BY Col15 ASC LIMIT 200",1),query({PREINVENTORY!$A:$O},"SELECT Col1, Col2, Col3, Col4, Col6, Col7, Col8, Col9, Col10, Col11, Col12, Col13, Col14 WHERE Col15 = 'X'")}

and

=QUERY(IMPORTRANGE("url", "INVENTORY!$A:$Z"),"SELECT Col1, Col2, Col3, Col4, Col5, Col15, Col17, Col18, Col7, Col11, Col12, Col13, Col14 WHERE Col15 IS NOT NULL and Col15 < "&F1&" and Col19 <> 'Printed' AND Col20 = 'Restock' ORDER BY Col15 ASC LIMIT 200",1)QUERY(IMPORTRANGE("url", "PREINVENTORY!$A3:$P2000"),"SELECT Col1, Col2, Col3, Col4, Col5, Col7, Col8, Col9, Col10, Col11, Col12, Col13, Col14 WHERE Col16 = 'X'")

Solution

  • try:

    ={QUERY(IMPORTRANGE("url", "INVENTORY!$A:$Z"), 
     "SELECT Col1,Col2,Col3,Col4,Col5,Col15,Col17,Col18,Col7,Col11,Col12,Col13,Col14 
      WHERE Col15 IS NOT NULL 
        AND Col15 < "&F1&" 
        AND Col19 <> 'Printed' 
        AND Col20 = 'Restock' 
      ORDER BY Col15 ASC 
      LIMIT 200", 1);
     QUERY(IMPORTRANGE("url", "PREINVENTORY!$A3:$P2000"),
     "SELECT Col1,Col2,Col3,Col4,Col5,Col7,Col8,Col9,Col10,Col11,Col12,Col13,Col14 
      WHERE Col16 = 'X'")}