Subject Re: [IBO] Need fastest record count for condition
Author James N Hitz
Try this:

SELECT parentField1,
parentField2,
parentFieldN,
(select count(*) from ChildTable
where ChildTable.ForeignKey = ParentTable.PrimaryKey)
AS ChildCount
FROM parentTable

...and then you can just read IBOQuery.FieldByName('ChildCount').AsInteger

James

ifitsx wrote:
>
> w/IBO 4.2Hd, D7, and Fb 1.54
>
> I'm working with a VirtualTreeview and two Tables:
>
> One Table contains data on the folder nodes for the
> VirtualTreeview, including whether the folder has
> any documents that it owns.
>
> The other Table contains rows for documents - notes -
> including a blob.
>
> The VirtualTreeview must know the exact count of
> child nodes it will have, when the parent node is created.
>
> This is currently maintained by a select statement on
> the notes table with the simple criteria for the folder parent node,
> and then using the IBOQuery.RecordCount value passed to the
> VirtualTreeview InitChildren event.
> <http://groups.yahoo.com/group/IBObjects/message/42693;_ylc=X3oDMTM1Y2twbWFhBF9TAzk3MzU5NzE0BGdycElkAzQwMjkzMARncnBzcElkAzE3MDUwMDcxODMEbXNnSWQDNDI2OTMEc2VjA2Z0cgRzbGsDdnRwYwRzdGltZQMxMjAzMDMzMjM2BHRwY0lkAzQyNjkz>
>
> <http://groups.yahoo.com/;_ylc=X3oDMTJjOGpmbm1iBF9TAzk3MzU5NzE0BGdycElkAzQwMjkzMARncnBzcElkAzE3MDUwMDcxODMEc2VjA2Z0cgRzbGsDZ2ZwBHN0aW1lAzEyMDMwMzMyMzY->
>
>
> <http://groups.yahoo.com/group/IBObjects;_ylc=X3oDMTJkYm05dmtwBF9TAzk3MzU5NzE0BGdycElkAzQwMjkzMARncnBzcElkAzE3MDUwMDcxODMEc2VjA3Z0bARzbGsDdmdocARzdGltZQMxMjAzMDMzMjM2>
>
>
> <http://us.ard.yahoo.com/SIG=13oi2p3hi/M=493064.12016257.12445664.8674578/D=groups/S=1705007183:NC/Y=YAHOO/EXP=1203040436/L=/B=QVSHANFJq10-/J=1203033236545420/A=4507179/R=0/SIG=12de4rskk/*http://us.rd.yahoo.com/evt=50284/*http://finance.yahoo.com/personal-finance>
>
> <http://us.ard.yahoo.com/SIG=13pdjsaf5/M=493064.12016300.12445692.11323196/D=groups/S=1705007183:NC/Y=YAHOO/EXP=1203040436/L=/B=QlSHANFJq10-/J=1203033236545420/A=5170418/R=0/SIG=11b5gu1oe/*http://new.groups.yahoo.com/specialKgroup>
>
> <http://us.ard.yahoo.com/SIG=13oo3h2d1/M=493064.12016263.12445670.8674578/D=groups/S=1705007183:NC/Y=YAHOO/EXP=1203040436/L=/B=Q1SHANFJq10-/J=1203033236545420/A=4836039/R=0/SIG=11olbte0b/*http://advision.webevents.yahoo.com/catzone/index.html>
>