Google Ads Query Language Grammar
Stay organized with collections
Save and categorize content based on your preferences.
ondemand_video
Video: Validating Queries
Here is the Google Ads Query Language grammar reference (in regular expression notation):
Query -> SelectClause FromClause WhereClause? OrderByClause?
LimitClause? ParametersClause?
SelectClause -> SELECT FieldName (, FieldName)*
FromClause -> FROM ResourceName
WhereClause -> WHERE Condition (AND Condition)*
OrderByClause -> ORDER BY Ordering (, Ordering)*
LimitClause -> LIMIT PositiveInteger
ParametersClause -> PARAMETERS Literal = Value (, Literal = Value)*
Condition -> FieldName Operator Value
Operator -> = | != | > | >= | < | <= | IN | NOT IN |
LIKE | NOT LIKE | CONTAINS ANY | CONTAINS ALL |
CONTAINS NONE | IS NULL | IS NOT NULL | DURING |
BETWEEN | REGEXP_MATCH | NOT REGEXP_MATCH
Value -> Literal | LiteralList | Number | NumberList | String |
StringList | Function
Ordering -> FieldName (ASC | DESC)?
FieldName -> [a-z] ([a-zA-Z0-9._])*
ResourceName -> [a-z] ([a-zA-Z_])*
StringList -> ( String (, String)* )
LiteralList -> ( Literal (, Literal)* )
NumberList -> ( Number (, Number)* )
PositiveInteger -> [1-9] ([0-9])*
Number -> -? [0-9]+ (. [0-9] [0-9]*)?
String -> (' Char* ') | (" Char* ")
Literal -> [a-zA-Z0-9_]*
Function -> LAST_14_DAYS | LAST_30_DAYS | LAST_7_DAYS |
LAST_BUSINESS_WEEK | LAST_MONTH | LAST_WEEK_MON_SUN |
LAST_WEEK_SUN_SAT | THIS_MONTH | THIS_WEEK_MON_TODAY |
THIS_WEEK_SUN_TODAY | TODAY | YESTERDAY
?
indicates an optional element
*
means zero or more; +
means one or more
(xxxxxx)
indicates a grouping
[a-z0-9]
signifies character ranges
|
stands for "or"
Rules and limitations
The REGEXP_MATCH
operator uses RE2
syntax.
To match a literal [
, ]
, %
, or _
using the LIKE
operator, surround
the character in square brackets. For example, the following condition matches
all campaign.name
values that start with [Earth_to_Mars]
:
campaign.name LIKE '[[]Earth[_]to[_]Mars[]]%'
The LIKE
operator can only be used on a string field, not an array.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-25 UTC.
[null,null,["Last updated 2025-08-25 UTC."],[[["\u003cp\u003eGoogle Ads Query Language (GAQL) uses a specific syntax to construct queries for retrieving data from Google Ads accounts, similar to SQL.\u003c/p\u003e\n"],["\u003cp\u003eGAQL supports various clauses like \u003ccode\u003eSELECT\u003c/code\u003e, \u003ccode\u003eFROM\u003c/code\u003e, \u003ccode\u003eWHERE\u003c/code\u003e, \u003ccode\u003eORDER BY\u003c/code\u003e, \u003ccode\u003eLIMIT\u003c/code\u003e, and \u003ccode\u003ePARAMETERS\u003c/code\u003e for data manipulation.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eWHERE\u003c/code\u003e clause allows filtering data based on conditions using operators like \u003ccode\u003e=\u003c/code\u003e, \u003ccode\u003e!=\u003c/code\u003e, \u003ccode\u003e>\u003c/code\u003e, \u003ccode\u003e<\u003c/code\u003e, \u003ccode\u003eIN\u003c/code\u003e, \u003ccode\u003eLIKE\u003c/code\u003e, \u003ccode\u003eCONTAINS\u003c/code\u003e, and others.\u003c/p\u003e\n"],["\u003cp\u003eGAQL provides built-in functions such as \u003ccode\u003eLAST_14_DAYS\u003c/code\u003e, \u003ccode\u003eTHIS_MONTH\u003c/code\u003e, \u003ccode\u003eTODAY\u003c/code\u003e, etc., for convenient date range selection within queries.\u003c/p\u003e\n"],["\u003cp\u003eWhen using operators like \u003ccode\u003eLIKE\u003c/code\u003e, special characters need to be escaped with square brackets for literal matching.\u003c/p\u003e\n"]]],[],null,["# Google Ads Query Language Grammar\n\nondemand_video\n[Video: Validating Queries](https://www.youtube.com/watch?v=pBpFEaXvADY&list=None&start=11)\n\nHere is the Google Ads Query Language grammar reference (in regular expression notation): \n\n```googlesql\nQuery -\u003e SelectClause FromClause WhereClause? OrderByClause?\n LimitClause? ParametersClause?\nSelectClause -\u003e SELECT FieldName (, FieldName)*\nFromClause -\u003e FROM ResourceName\nWhereClause -\u003e WHERE Condition (AND Condition)*\nOrderByClause -\u003e ORDER BY Ordering (, Ordering)*\nLimitClause -\u003e LIMIT PositiveInteger\nParametersClause -\u003e PARAMETERS Literal = Value (, Literal = Value)*\n\nCondition -\u003e FieldName Operator Value\nOperator -\u003e = | != | \u003e | \u003e= | \u003c | \u003c= | IN | NOT IN |\n LIKE | NOT LIKE | CONTAINS ANY | CONTAINS ALL |\n CONTAINS NONE | IS NULL | IS NOT NULL | DURING |\n BETWEEN | REGEXP_MATCH | NOT REGEXP_MATCH\nValue -\u003e Literal | LiteralList | Number | NumberList | String |\n StringList | Function\nOrdering -\u003e FieldName (ASC | DESC)?\n\nFieldName -\u003e [a-z] ([a-zA-Z0-9._])*\nResourceName -\u003e [a-z] ([a-zA-Z_])*\n\nStringList -\u003e ( String (, String)* )\nLiteralList -\u003e ( Literal (, Literal)* )\nNumberList -\u003e ( Number (, Number)* )\n\nPositiveInteger -\u003e [1-9] ([0-9])*\nNumber -\u003e -? [0-9]+ (. [0-9] [0-9]*)?\nString -\u003e (' Char* ') | (\" Char* \")\nLiteral -\u003e [a-zA-Z0-9_]*\n\nFunction -\u003e LAST_14_DAYS | LAST_30_DAYS | LAST_7_DAYS |\n LAST_BUSINESS_WEEK | LAST_MONTH | LAST_WEEK_MON_SUN |\n LAST_WEEK_SUN_SAT | THIS_MONTH | THIS_WEEK_MON_TODAY |\n THIS_WEEK_SUN_TODAY | TODAY | YESTERDAY\n```\n\n`?`indicates an optional element \n\n`*` means zero or more; `+` means one or more \n\n`(xxxxxx)` indicates a grouping \n\n`[a-z0-9]` signifies character ranges \n\n`|` stands for \"or\"\n\nRules and limitations\n---------------------\n\n- The `REGEXP_MATCH` operator uses [RE2\n syntax](//github.com/google/re2/wiki/Syntax).\n\n- To match a literal `[`, `]`, `%`, or `_` using the `LIKE` operator, surround\n the character in square brackets. For example, the following condition matches\n all `campaign.name` values that start with `[Earth_to_Mars]`:\n\n campaign.name LIKE '[[]Earth[_]to[_]Mars[]]%'\n\n- The `LIKE` operator can only be used on a string field, not an array."]]