getTableAlias()
Returns the alias name previously defined when creating a subquery via subQuery('alias')
.
This is helpful when referencing the subquery later in JOINs, WHERE clauses, or when generating raw SQL manually.
Signature:
public function getTableAlias(): string|null
Example
// Create subquery with alias 'recent_orders'
$sub = $db->subQuery('recent_orders');
$sub->where('status', 'confirmed');
$sub->groupBy('user_id');
// Get alias
$alias = $sub->getTableAlias(); // returns 'recent_orders'
Use Cases
- Reference subqueries by alias when building complex queries
- Use in JOIN ON conditions or custom WHERE clauses
- Debug or log subquery structure with alias identification