class SQLSelect extends SQLConditionalExpression (View source)

Object representing a SQL SELECT query.

The various parts of the SQL query can be manipulated individually.

Properties

protected array $replacementsOld

Keep an internal register of find/replace pairs to execute when it's time to actually get the query SQL.

from  SQLExpression
protected array $replacementsNew

Keep an internal register of find/replace pairs to execute when it's time to actually get the query SQL.

from  SQLExpression
protected array $where

An array of WHERE clauses.

from  SQLConditionalExpression
protected string $connective

The logical connective used to join WHERE clauses. Defaults to AND.

from  SQLConditionalExpression
protected array $from

An array of tables. The first one is just the table name.

from  SQLConditionalExpression
protected array $select

An array of SELECT fields, keyed by an optional alias.

protected array $groupby

An array of GROUP BY clauses.

protected array $having

An array of having clauses.

protected bool $distinct

If this is true DISTINCT will be added to the SQL.

protected string $orderby

An array of ORDER BY clauses, functions. Stores as an associative array of column / function to direction.

protected array $limit

An array containing limit and offset keys for LIMIT clause.

Methods

public
__get($field) deprecated

No description

public
__set($field, $value) deprecated

No description

public
replaceText(string $old, string $new)

Swap some text in the SQL query with another.

public
string
__toString()

Return the generated SQL string for this query

public
renameTable(string $old, string $new)

Swap the use of one table with another.

public
bool
isEmpty()

Determine if this query is empty, and thus cannot be executed

public
string
sql(array $parameters = array())

Generate the SQL statement for this query.

public
execute()

Execute this query.

protected
copyTo(SQLExpression $object)

Copies the query parameters contained in this object to another SQLExpression

public
__construct(array $select = "*", array|string $from = array(), array $where = array(), array $orderby = array(), array $groupby = array(), array $having = array(), array|string $limit = array())

Construct a new SQLSelect.

public
setFrom(string|array $from)

Sets the list of tables to query from or update

public
addFrom(string|array $from)

Add a table to include in the query or update

public
setConnective(string $value)

Set the connective property.

public
string
getConnective()

Get the connective property.

public
useDisjunction()

Use the disjunctive operator 'OR' to join filter expressions in the WHERE clause.

public
useConjunction()

Use the conjunctive operator 'AND' to join filter expressions in the WHERE clause.

public
addLeftJoin(string $table, string $onPredicate, string $tableAlias = '', int $order = 20, array $parameters = array())

Add a LEFT JOIN criteria to the tables list.

public
addInnerJoin(string $table, string $onPredicate, string $tableAlias = null, int $order = 20, array $parameters = array())

Add an INNER JOIN criteria

public
addFilterToJoin(string $table, string $filter)

Add an additional filter (part of the ON clause) on a join.

public
setJoinFilter(string $table, string $filter)

Set the filter (part of the ON clause) on a join.

public
bool
isJoinedTo(string $tableAlias)

Returns true if we are already joining to the given table alias

public
array
queriedTables()

Return a list of tables that this query is selecting from.

public
array
getFrom()

Return a list of tables queried

public
array
getJoins(array $parameters = array())

Retrieves the finalised list of joins

protected
array
getOrderedJoins($from)

Ensure that framework "auto-generated" table JOINs are first in the finalised SQL query.

protected
mergesort(array $array, callable $cmpFunction = 'strcmp')

Since uasort don't preserve the order of an array if the comparison is equal we have to resort to a merge sort. It's quick and stable: O(n*log(n)).

public
setWhere(mixed $where)

Set a WHERE clause.

public
addWhere(mixed $where)

Adds a WHERE clause.

public
setWhereAny(mixed $filters)

No description

public
addWhereAny(mixed $filters)

No description

public
array
getWhere()

Return a list of WHERE clauses used internally.

public
array
getWhereParameterised(array $parameters)

Return a list of WHERE clauses used internally.

protected
parsePredicate(string|int $key, mixed $value)

Given a key / value pair, extract the predicate and any potential paramaters in a format suitable for storing internally as a list of paramaterised conditions.

protected
array
normalisePredicates(array $predicates)

Given a list of conditions in any user-acceptable format, convert this to an array of paramaterised predicates suitable for merging with $this->where.

public
splitQueryParameters(array $conditions, array $predicates, array $parameters)

Given a list of conditions as per the format of $this->where, split this into an array of predicates, and a separate array of ordered parameters

public
bool
filtersOnID()

Checks whether this query is for a specific ID in a table

public
bool
filtersOnFK()

Checks whether this query is filtering on a foreign key, ie finding a has_many relationship

public
toDelete()

Generates an SQLDelete object using the currently specified parameters

public
toSelect()

Generates an SQLSelect object using the currently specified parameters.

public
toUpdate()

Generates an SQLUpdate object using the currently specified parameters.

public static 
create(array $select = "*", array|string $from = array(), array $where = array(), array $orderby = array(), array $groupby = array(), array $having = array(), array|string $limit = array())

Construct a new SQLSelect.

public
$this
setSelect(string|array $fields)

Set the list of columns to be selected by the query.

public
$this
addSelect(string|array $fields)

Add to the list of columns to be selected by the query.

public
$this
selectField(string $field, string|null $alias = null)

Select an additional field.

public
string
expressionForField(string $field)

Return the SQL expression for the given field alias.

public
setDistinct(bool $value)

Set distinct property.

public
bool
getDistinct()

Get the distinct property.

public
array
getLimit()

Get the limit property.

public
setLimit(int|string|array $limit, int $offset = 0)

Pass LIMIT clause either as SQL snippet or in array format.

public
$this
setOrderBy(string|array $clauses = null, string $direction = null)

Set ORDER BY clause either as SQL snippet or in array format.

public
$this
addOrderBy(string|array $clauses = null, string $direction = null)

Add ORDER BY clause either as SQL snippet or in array format.

public
array
getOrderBy()

Returns the current order by as array if not already. To handle legacy statements which are stored as strings. Without clauses and directions, convert the orderby clause to something readable.

public
reverseOrderBy()

Reverses the order by clause by replacing ASC or DESC references in the current order by with it's corollary.

public
setGroupBy(string|array $groupby)

Set a GROUP BY clause.

public
addGroupBy(string|array $groupby)

Add a GROUP BY clause.

public
setHaving(mixed $having)

Set a HAVING clause.

public
addHaving(mixed $having)

Add a HAVING clause

public
array
getHaving()

Return a list of HAVING clauses used internally.

public
array
getHavingParameterised(array $parameters)

Return a list of HAVING clauses used internally.

public
array
getGroupBy()

Return a list of GROUP BY clauses used internally.

public
array
getSelect()

Return an itemised select list as a map, where keys are the aliases, and values are the column sources.

public
int
unlimitedRowCount(string $column = null)

Return the number of rows in this query if the limit were removed. Useful in paged data sets.

public
bool
canSortBy(string $fieldName)

Returns true if this query can be sorted by the given field.

public
int
count(string $column = null)

Return the number of rows in this query, respecting limit and offset.

public
aggregate(string $column, string $alias = null)

Return a new SQLSelect that calls the given aggregate functions on this data.

public
firstRow()

Returns a query that returns only the first row of this query

public
lastRow()

Returns a query that returns only the last row of this query

Details

__get($field) deprecated

deprecated since version 4.0

No description

Parameters

$field

__set($field, $value) deprecated

deprecated since version 4.0

No description

Parameters

$field
$value

replaceText(string $old, string $new)

Swap some text in the SQL query with another.

Note that values in parameters will not be replaced

Parameters

string $old

The old text (escaped)

string $new

The new text (escaped)

string __toString()

Return the generated SQL string for this query

Is it ok for this to consider parameters? Test cases here!

Return Value

string

renameTable(string $old, string $new)

Swap the use of one table with another.

Parameters

string $old

Name of the old table (unquoted, escaped)

string $new

Name of the new table (unquoted, escaped)

bool isEmpty()

Determine if this query is empty, and thus cannot be executed

Return Value

bool

Flag indicating that this query is empty

string sql(array $parameters = array())

Generate the SQL statement for this query.

Parameters

array $parameters

Out variable for parameters required for this query

Return Value

string

The completed SQL query

SS_Query execute()

Execute this query.

Return Value

SS_Query

protected copyTo(SQLExpression $object)

Copies the query parameters contained in this object to another SQLExpression

Parameters

SQLExpression $object

__construct(array $select = "*", array|string $from = array(), array $where = array(), array $orderby = array(), array $groupby = array(), array $having = array(), array|string $limit = array())

Construct a new SQLSelect.

Parameters

array $select

An array of SELECT fields.

array|string $from

An array of Tables (FROM clauses). The first one should be just the table name.

array $where

An array of WHERE clauses.

array $orderby

An array ORDER BY clause.

array $groupby

An array of GROUP BY clauses.

array $having

An array of HAVING clauses.

array|string $limit

A LIMIT clause or array with limit and offset keys

SQLConditionalExpression setFrom(string|array $from)

Sets the list of tables to query from or update

Parameters

string|array $from

Single, or list of, ANSI quoted table names

Return Value

SQLConditionalExpression

Examples

$query->setFrom('"MyTable"'); // SELECT * FROM "MyTable"

SQLConditionalExpression addFrom(string|array $from)

Add a table to include in the query or update

Parameters

string|array $from

Single, or list of, ANSI quoted table names

Return Value

SQLConditionalExpression

Self reference

Examples

$query->addFrom('"MyTable"'); // SELECT * FROM "MyTable"

setConnective(string $value)

Set the connective property.

Parameters

string $value

either 'AND' or 'OR'

string getConnective()

Get the connective property.

Return Value

string

'AND' or 'OR'

useDisjunction()

Use the disjunctive operator 'OR' to join filter expressions in the WHERE clause.

useConjunction()

Use the conjunctive operator 'AND' to join filter expressions in the WHERE clause.

SQLConditionalExpression addLeftJoin(string $table, string $onPredicate, string $tableAlias = '', int $order = 20, array $parameters = array())

Add a LEFT JOIN criteria to the tables list.

Parameters

string $table

Unquoted table name

string $onPredicate

The "ON" SQL fragment in a "LEFT JOIN ... AS ... ON ..." statement, Needs to be valid (quoted) SQL.

string $tableAlias

Optional alias which makes it easier to identify and replace joins later on

int $order

A numerical index to control the order that joins are added to the query; lower order values will cause the query to appear first. The default is 20, and joins created automatically by the ORM have a value of 10.

array $parameters

Any additional parameters if the join is a parameterised subquery

Return Value

SQLConditionalExpression

Self reference

SQLConditionalExpression addInnerJoin(string $table, string $onPredicate, string $tableAlias = null, int $order = 20, array $parameters = array())

Add an INNER JOIN criteria

Parameters

string $table

Unquoted table name

string $onPredicate

The "ON" SQL fragment in an "INNER JOIN ... AS ... ON ..." statement. Needs to be valid (quoted) SQL.

string $tableAlias

Optional alias which makes it easier to identify and replace joins later on

int $order

A numerical index to control the order that joins are added to the query; lower order values will cause the query to appear first. The default is 20, and joins created automatically by the ORM have a value of 10.

array $parameters

Any additional parameters if the join is a parameterised subquery

Return Value

SQLConditionalExpression

Self reference

SQLConditionalExpression addFilterToJoin(string $table, string $filter)

Add an additional filter (part of the ON clause) on a join.

Parameters

string $table

Table to join on from the original join (unquoted)

string $filter

The "ON" SQL fragment (escaped)

Return Value

SQLConditionalExpression

Self reference

SQLConditionalExpression setJoinFilter(string $table, string $filter)

Set the filter (part of the ON clause) on a join.

Parameters

string $table

Table to join on from the original join (unquoted)

string $filter

The "ON" SQL fragment (escaped)

Return Value

SQLConditionalExpression

Self reference

bool isJoinedTo(string $tableAlias)

Returns true if we are already joining to the given table alias

Parameters

string $tableAlias

Table name

Return Value

bool

array queriedTables()

Return a list of tables that this query is selecting from.

Return Value

array

Unquoted table names

array getFrom()

Return a list of tables queried

Return Value

array

array getJoins(array $parameters = array())

Retrieves the finalised list of joins

This part of the code could be simplified

Parameters

array $parameters

Out variable for parameters required for this query

Return Value

array

List of joins as a mapping from array('Alias' => 'Join Expression')

protected array getOrderedJoins($from)

Ensure that framework "auto-generated" table JOINs are first in the finalised SQL query.

This prevents issues where developer-initiated JOINs attempt to JOIN using relations that haven't actually yet been scaffolded by the framework. Demonstrated by PostGres in errors like: "...ERROR: missing FROM-clause..."

Parameters

$from

array - in the format of $this->from

Return Value

array
  • and reorderded list of selects

protected mergesort(array $array, callable $cmpFunction = 'strcmp')

Since uasort don't preserve the order of an array if the comparison is equal we have to resort to a merge sort. It's quick and stable: O(n*log(n)).

Parameters

array $array
  • the array to sort
callable $cmpFunction
  • the function to use for comparison

See also

http://stackoverflow.com/q/4353739/139301

SQLConditionalExpression setWhere(mixed $where)

Set a WHERE clause.

Parameters

mixed $where

Predicate(s) to set, as escaped SQL statements or paramaterised queries

Return Value

SQLConditionalExpression

Self reference

See also

SQLConditionalExpression::addWhere for syntax examples

SQLConditionalExpression addWhere(mixed $where)

Adds a WHERE clause.

Note that the database will execute any parameterised queries using prepared statements whenever available.

There are several different ways of doing this.

 // the entire predicate as a single string
 $query->addWhere("\"Column\" = 'Value'");

 // multiple predicates as an array
 $query->addWhere(array("\"Column\" = 'Value'", "\"Column\" != 'Value'"));

 // Shorthand for the above using argument expansion
 $query->addWhere("\"Column\" = 'Value'", "\"Column\" != 'Value'");

 // multiple predicates with parameters
 $query->addWhere(array('"Column" = ?' => $column, '"Name" = ?' => $value)));

 // Shorthand for simple column comparison (as above), omitting the '?'
 $query->addWhere(array('"Column"' => $column, '"Name"' => $value));

 // Multiple predicates, each with multiple parameters.
 $query->addWhere(array(
    '"ColumnOne" = ? OR "ColumnTwo" != ?' => array(1, 4),
    '"ID" != ?' => $value
));

// Using a dynamically generated condition (any object that implements SQLConditionGroup)
$condition = new ObjectThatImplements_SQLConditionGroup();
$query->addWhere($condition);

Note that if giving multiple parameters for a single predicate the array of values must be given as an indexed array, not an associative array.

Also should be noted is that any null values for parameters may give unexpected behaviour. array('Column' => NULL) is shorthand for array('Column = ?', NULL), and will not match null values for that column, as 'Column IS NULL' is the correct syntax.

Additionally, be careful of key conflicts. Adding two predicates with the same condition but different parameters can cause a key conflict if added in the same array. This can be solved by wrapping each individual condition in an array. E.g.

// Multiple predicates with duplicate conditions
 $query->addWhere(array(
    array('ID != ?' => 5),
    array('ID != ?' => 6)
));

// Alternatively this can be added in two separate calls to addWhere
$query->addWhere(array('ID != ?' => 5));
$query->addWhere(array('ID != ?' => 6));

// Or simply omit the outer array
$query->addWhere(array('ID != ?' => 5), array('ID != ?' => 6));

If it's necessary to force the parameter to be considered as a specific data type by the database connector's prepared query processor any parameter can be cast to that type by using the following format.

 // Treat this value as a double type, regardless of its type within PHP
 $query->addWhere(array(
    'Column' => array(
        'value' => $variable,
        'type' => 'double'
    )
));

Parameters

mixed $where

Predicate(s) to set, as escaped SQL statements or paramaterised queries

Return Value

SQLConditionalExpression

Self reference

SQLConditionalExpression setWhereAny(mixed $filters)

No description

Parameters

mixed $filters

Predicate(s) to set, as escaped SQL statements or paramaterised queries

Return Value

SQLConditionalExpression

Self reference

See also

SQLConditionalExpression::addWhere

SQLConditionalExpression addWhereAny(mixed $filters)

No description

Parameters

mixed $filters

Predicate(s) to set, as escaped SQL statements or paramaterised queries

Return Value

SQLConditionalExpression

Self reference

See also

SQLConditionalExpression::addWhere

array getWhere()

Return a list of WHERE clauses used internally.

Return Value

array

array getWhereParameterised(array $parameters)

Return a list of WHERE clauses used internally.

Parameters

array $parameters

Out variable for parameters required for this query

Return Value

array

protected array|SQLConditionGroup parsePredicate(string|int $key, mixed $value)

Given a key / value pair, extract the predicate and any potential paramaters in a format suitable for storing internally as a list of paramaterised conditions.

Parameters

string|int $key

The left hand (key index) of this condition. Could be the predicate or an integer index.

mixed $value

The The right hand (array value) of this condition. Could be the predicate (if non-paramaterised), or the parameter(s). Could also be an array containing a nested condition in the similar format this function outputs.

Return Value

array|SQLConditionGroup

A single item array in the format array($predicate => array($parameters)), unless it's a SQLConditionGroup

protected array normalisePredicates(array $predicates)

Given a list of conditions in any user-acceptable format, convert this to an array of paramaterised predicates suitable for merging with $this->where.

Normalised predicates are in the below format, in order to avoid key collisions.

array(
array('Condition != ?' => array('parameter')),
array('Condition != ?' => array('otherparameter')),
array('Condition = 3' => array()),
array('Condition = ? OR Condition = ?' => array('parameter1', 'parameter2))
)

Parameters

array $predicates

List of predicates. These should be wrapped in an array one level more than for addWhere, as query expansion is not supported here.

Return Value

array

List of normalised predicates

splitQueryParameters(array $conditions, array $predicates, array $parameters)

Given a list of conditions as per the format of $this->where, split this into an array of predicates, and a separate array of ordered parameters

Note, that any SQLConditionGroup objects will be evaluated here.

Parameters

array $conditions

List of Conditions including parameters

array $predicates

Out parameter for the list of string predicates

array $parameters

Out parameter for the list of parameters

See also

SQLConditionGroup

bool filtersOnID()

Checks whether this query is for a specific ID in a table

Doesn't work with combined statements (e.g. "Foo='bar' AND ID=5")

Return Value

bool

bool filtersOnFK()

Checks whether this query is filtering on a foreign key, ie finding a has_many relationship

Doesn't work with combined statements (e.g. "Foo='bar' AND ParentID=5")

Return Value

bool

SQLDelete toDelete()

Generates an SQLDelete object using the currently specified parameters

Return Value

SQLDelete

SQLSelect toSelect()

Generates an SQLSelect object using the currently specified parameters.

Return Value

SQLSelect

SQLUpdate toUpdate()

Generates an SQLUpdate object using the currently specified parameters.

No fields will have any assigned values for the newly generated SQLUpdate object.

Return Value

SQLUpdate

static SQLSelect create(array $select = "*", array|string $from = array(), array $where = array(), array $orderby = array(), array $groupby = array(), array $having = array(), array|string $limit = array())

Construct a new SQLSelect.

Parameters

array $select

An array of SELECT fields.

array|string $from

An array of FROM clauses. The first one should be just the table name. Each should be ANSI quoted.

array $where

An array of WHERE clauses.

array $orderby

An array ORDER BY clause.

array $groupby

An array of GROUP BY clauses.

array $having

An array of HAVING clauses.

array|string $limit

A LIMIT clause or array with limit and offset keys

Return Value

SQLSelect

$this setSelect(string|array $fields)

Set the list of columns to be selected by the query.

 // pass fields to select as single parameter array
 $query->setSelect(array('"Col1"', '"Col2"'))->setFrom('"MyTable"');

 // pass fields to select as multiple parameters
 $query->setSelect('"Col1"', '"Col2"')->setFrom('"MyTable"');

 // Set a list of selected fields as aliases
 $query->setSelect(array('Name' => '"Col1"', 'Details' => '"Col2"')->setFrom('"MyTable"');

Parameters

string|array $fields

Field names should be ANSI SQL quoted. Array keys should be unquoted.

Return Value

$this

Self reference

$this addSelect(string|array $fields)

Add to the list of columns to be selected by the query.

Parameters

string|array $fields

Field names should be ANSI SQL quoted. Array keys should be unquoted.

Return Value

$this

Self reference

See also

setSelect for example usage

$this selectField(string $field, string|null $alias = null)

Select an additional field.

Parameters

string $field

The field to select (ansi quoted SQL identifier or statement)

string|null $alias

The alias of that field (unquoted SQL identifier). Defaults to the unquoted column name of the $field parameter.

Return Value

$this

Self reference

string expressionForField(string $field)

Return the SQL expression for the given field alias.

Returns null if the given alias doesn't exist. See selectField() for details on alias generation.

Parameters

string $field

Return Value

string

SQLSelect setDistinct(bool $value)

Set distinct property.

Parameters

bool $value

Return Value

SQLSelect

Self reference

bool getDistinct()

Get the distinct property.

Return Value

bool

array getLimit()

Get the limit property.

Return Value

array

SQLSelect setLimit(int|string|array $limit, int $offset = 0)

Pass LIMIT clause either as SQL snippet or in array format.

Internally, limit will always be stored as a map containing the keys 'start' and 'limit'

Parameters

int|string|array $limit

If passed as a string or array, assumes SQL escaped data. Only applies for positive values, or if an $offset is set as well.

int $offset

Return Value

SQLSelect

Self reference

Exceptions

InvalidArgumentException

$this setOrderBy(string|array $clauses = null, string $direction = null)

Set ORDER BY clause either as SQL snippet or in array format.

Parameters

string|array $clauses

Clauses to add (escaped SQL statement)

string $direction

Sort direction, ASC or DESC

Return Value

$this

Self reference

Examples

$sql->setOrderBy("Column");
$sql->setOrderBy("Column DESC");
$sql->setOrderBy("Column DESC, ColumnTwo ASC");
$sql->setOrderBy("Column", "DESC");
$sql->setOrderBy(array("Column" => "ASC", "ColumnTwo" => "DESC"));

$this addOrderBy(string|array $clauses = null, string $direction = null)

Add ORDER BY clause either as SQL snippet or in array format.

Parameters

string|array $clauses

Clauses to add (escaped SQL statements)

string $direction

Sort direction, ASC or DESC

Return Value

$this

Self reference

Examples

$sql->addOrderBy("Column");
$sql->addOrderBy("Column DESC");
$sql->addOrderBy("Column DESC, ColumnTwo ASC");
$sql->addOrderBy("Column", "DESC");
$sql->addOrderBy(array("Column" => "ASC", "ColumnTwo" => "DESC"));

array getOrderBy()

Returns the current order by as array if not already. To handle legacy statements which are stored as strings. Without clauses and directions, convert the orderby clause to something readable.

Return Value

array

SQLSelect reverseOrderBy()

Reverses the order by clause by replacing ASC or DESC references in the current order by with it's corollary.

Return Value

SQLSelect

Self reference

SQLSelect setGroupBy(string|array $groupby)

Set a GROUP BY clause.

Parameters

string|array $groupby

Escaped SQL statement

Return Value

SQLSelect

Self reference

SQLSelect addGroupBy(string|array $groupby)

Add a GROUP BY clause.

Parameters

string|array $groupby

Escaped SQL statement

Return Value

SQLSelect

Self reference

SQLSelect setHaving(mixed $having)

Set a HAVING clause.

Parameters

mixed $having

Predicate(s) to set, as escaped SQL statements or paramaterised queries

Return Value

SQLSelect

Self reference

See also

\SQLSelect::addWhere() for syntax examples

SQLSelect addHaving(mixed $having)

Add a HAVING clause

Parameters

mixed $having

Predicate(s) to set, as escaped SQL statements or paramaterised queries

Return Value

SQLSelect

Self reference

See also

\SQLSelect::addWhere() for syntax examples

array getHaving()

Return a list of HAVING clauses used internally.

Return Value

array

array getHavingParameterised(array $parameters)

Return a list of HAVING clauses used internally.

Parameters

array $parameters

Out variable for parameters required for this query

Return Value

array

array getGroupBy()

Return a list of GROUP BY clauses used internally.

Return Value

array

array getSelect()

Return an itemised select list as a map, where keys are the aliases, and values are the column sources.

Aliases will always be provided (if the alias is implicit, the alias value will be inferred), and won't be quoted. E.g., 'Title' => '"SiteTree"."Title"'.

Return Value

array

int unlimitedRowCount(string $column = null)

Return the number of rows in this query if the limit were removed. Useful in paged data sets.

Parameters

string $column

Return Value

int

bool canSortBy(string $fieldName)

Returns true if this query can be sorted by the given field.

Parameters

string $fieldName

Return Value

bool

int count(string $column = null)

Return the number of rows in this query, respecting limit and offset.

Parameters

string $column

Quoted, escaped column name

Return Value

int

SQLSelect aggregate(string $column, string $alias = null)

Return a new SQLSelect that calls the given aggregate functions on this data.

Parameters

string $column

An aggregate expression, such as 'MAX("Balance")', or a set of them (as an escaped SQL statement)

string $alias

An optional alias for the aggregate column.

Return Value

SQLSelect

A clone of this object with the given aggregate function

SQLSelect firstRow()

Returns a query that returns only the first row of this query

Return Value

SQLSelect

A clone of this object with the first row only

SQLSelect lastRow()

Returns a query that returns only the last row of this query

Return Value

SQLSelect

A clone of this object with the last row only