selectOnly<T extends HasResultSet, R> method
- ResultSetImplementation<
T, R> table, - {bool distinct = false}
Starts a complex statement on table
that doesn't necessarily use all of
table
's columns.
Unlike select, which automatically selects all columns of table
, this
method is suitable for more advanced queries that can use table
without
using their column. As an example, assuming we have a table comments
with a TextColumn content
, this query would report the average length of
a comment:
Stream<num> watchAverageCommentLength() {
final avgLength = comments.content.length.avg();
final query = selectOnly(comments)
..addColumns([avgLength]);
return query.map((row) => row.read(avgLength)).watchSingle();
}
While this query reads from comments
, it doesn't use all of it's columns
(in fact, it uses none of them!). This makes it suitable for
selectOnly instead of select.
The distinct
parameter (defaults to false) can be used to remove
duplicate rows from the result set.
For simple queries, use select.
See also:
- the documentation on aggregate expressions
- the documentation on group by
Implementation
JoinedSelectStatement<T, R> selectOnly<T extends HasResultSet, R>(
ResultSetImplementation<T, R> table,
{bool distinct = false}) {
return JoinedSelectStatement<T, R>(
resolvedEngine, table, [], distinct, false, false);
}