webCOMAND

query::select()

Add one or more fields or columns to the query SELECT clause. The select method takes any number of field/expression parameters. Each parameter may be a single string that represents the field Identifier or expression, an array of strings, or a cQL Array.

Prototype

select(mixed $fields): query

Parameters

  • fields - A list of fields/expressions to select into the results in one of the following forms.
    • String - a full or partial comma-separated cQL SELECT clause.
    • Array - an array of individual fields/expressions to select.
    • Multiple Parameters - Instead of passing a single array of fields/expressions, each field/expression can be passed as a separate parameter.

Return

The updated query object is returned.  This is handy for chaining additional methods.

Example

// simple query with SELECT and FROM clauses
$query = $repo->query();
$query->select('Name', 'Age');
$query->from('Contact');

// similar query with string aliases
$query = $repo->query();
$query->select('Name AS FullName', 'Age AS TotalYears');
$query->from('Contact');

// similar query with expression array aliases
$query = $repo->query();
$query->select(
	['AS', 'Name', 'FullName'],
	['AS', 'Age', 'YearOld']
);
$query->from('Contact');

// similar query with aggregate function and alias
$query = $repo->query();
$query->select('SUM(Age) AS TotalYears');
$query->from('Contact');

// similar query with expression array
$query = $repo->query();
$query->select([
	'AS',
	['SUM', 'Age'],
	'YearOld'
]);
$query->from('Contact');