Firebird 2.1 Language Reference Update
Firebird 2.1 Language Reference Update
Firebird 2.1 Language Reference Update
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
DML statements<br />
select d.dept_no,<br />
d.indent || d.department as department,<br />
dyb_2008.budget as budget_08,<br />
dyb_2009.budget as budget_09<br />
from dept_tree d<br />
left join dept_year_budget dyb_2008<br />
on d.dept_no = dyb_2008.dept_no<br />
and dyb_2008.fiscal_year = 2008<br />
left join dept_year_budget dyb_2009<br />
on d.dept_no = dyb_2009.dept_no<br />
and dyb_2009.fiscal_year = 2009<br />
Notes on recursive CTEs:<br />
• Aggregates (DISTINCT, GROUP BY, HAVING) and aggregate functions (SUM, COUNT, MAX etc) are not<br />
allowed in recursive union members.<br />
• A recursive reference cannot participate in an outer join.<br />
• The maximum recursion depth is 1024.<br />
Derived tables (“SELECT FROM SELECT”)<br />
Added in: 2.0<br />
Description: A derived table is the result set of a SELECT query, used in an outer SELECT as if it were an ordinary<br />
table. Put otherwise, it is a subquery in the FROM clause.<br />
Syntax:<br />
Examples:<br />
(select-query)<br />
[[AS] derived-table-alias]<br />
[()]<br />
:= column-alias [, column-alias ...]<br />
The derived table in the query below (shown in boldface) contains all the relation names in the<br />
database followed by their field count. The outer SELECT produces, for each existing field count, the<br />
number of relations having that field count.<br />
select fieldcount,<br />
count(relation) as num_tables<br />
from (select r.rdb$relation_name as relation,<br />
count(*) as fieldcount<br />
from rdb$relations r<br />
join rdb$relation_fields rf<br />
on rf.rdb$relation_name = r.rdb$relation_name<br />
group by relation)<br />
group by fieldcount<br />
A trivial example demonstrating the use of a derived table alias and column aliases list (both are<br />
optional):<br />
71