Skip to content

Chained CRUD - Aggregate Terminal Methods

Aggregate methods directly return calculation results without manually building SELECT COUNT(*) FROM .... For architecture details, see Chained CRUD Overview.


RowCount - Count Rows

Syntax

vb
Function RowCount() As Long

Example

vb
' Count total rows
Dim total As Long
total = db.Table("users").RowCount

' Conditional count
Dim activeCount As Long
activeCount = db.Table("users").Where("status=?", "active").RowCount

' Range count
Dim youngCount As Long
youngCount = db.Table("users").WhereBetween("age", 18, 30).RowCount

RowExists - Check Existence

Syntax

vb
Function RowExists() As Boolean

Example

vb
' Check if user exists
If db.Table("users").Where("serial_no=?", sn).RowExists Then
    MsgBox "Device already exists"
Else
    MsgBox "Device does not exist"
End If

' Check if email is registered
If db.Table("users").Where("email=?", email).RowExists Then
    MsgBox "Email already registered"
End If

RowPluck - Extract Single Column Value List

Returns a Collection containing all values of the specified field.

Syntax

vb
Function RowPluck(ByVal FieldName As String) As Collection

Example

vb
' Extract all usernames
Dim names As Collection
Set names = db.Table("users").RowPluck("name")

' Extract IDs meeting conditions
Dim ids As Collection
Set ids = db.Table("users").Where("role=?", "admin").RowPluck("id")

' Iterate extracted results
Dim v As Variant
For Each v In ids
    Debug.Print "Admin ID: " & v
Next

RowMax - Maximum Value

Syntax

vb
Function RowMax(ByVal FieldName As String) As Variant

Example

vb
Dim maxAge As Variant
maxAge = db.Table("users").RowMax("age")
Debug.Print "Maximum age: " & maxAge

' Conditional maximum
Dim maxSalary As Variant
maxSalary = db.Table("users").Where("dept=?", "IT").RowMax("salary")

RowMin - Minimum Value

vb
Dim minAge As Variant
minAge = db.Table("users").RowMin("age")

RowSum - Sum

vb
Dim totalAmount As Variant
totalAmount = db.Table("orders").Where("year=?", 2026).RowSum("amount")
Debug.Print "2026 total amount: " & totalAmount

RowAvg - Average

vb
Dim avgSalary As Variant
avgSalary = db.Table("users").Where("dept=?", "IT").RowAvg("salary")
Debug.Print "IT department average salary: " & avgSalary

Last Updated: 2026-06-26

VB6 and LOGO copyright of Microsoft Corporation