Previous Next JavaScript must be enabled to correctly display this content

## Using External Variables

Using external variables lets a query to written and compiled once, and then run multiple times with different values for the external variables. Binding the external variables to specific values is done through APIs, which you use before executing the query.

You must declare external variables in your SQL query before referencing them in the SELECT statement. For example:

    DECLARE $age integer;
    SELECT firstname, lastname, age
    FROM Users
    WHERE age > $age;

If the variable $age is set to value 39, the result of the above query is:

    +-----------+----------+-----+
    | firstname | lastname | age |
    +-----------+----------+-----+
    | Dana      | Scully   |  47 |
    +-----------+----------+-----+