\Drupal\Core\Database\Query\Select::addExpression
public
function
Adds an expression to the list of "fields" to be SELECTed.

Adds an expression to the list of "fields" to be SELECTed.

An expression can be any arbitrary string that is valid SQL. That includes various functions, which may in some cases be database-dependent. This method makes no effort to correct for database-specific functions.

Comments

isholgueras’s picture

An example of an expression with the CONCAT method could be:

$query->addExpression("concat(city,' - ',country)", "place");

With this, you can get a column in your query named "place" with a concat of two columns. Something like:

|      place      |
-------------------
| Madrid - Spain  |
| Paris - France  |