Subject | Re: [ib-support] Is a joined query faster than a subquery, or doesn't it matter? |
---|---|
Author | Jörg Schiemann |
Post date | 2001-02-14T14:33:26Z |
>>2) When you select with an order by, you should use the subselect.Bu because SampleDetail.MasterID is a foreign key, I don't need to set up
>I'd expect it to not matter all too much, but unless you wanted to order on
>the subselect (in which case I'd definetely recommend a join), I guess
>you're right in that it could be faster.
>The most important will be to have correct indices. You've already got your
>primary keys, in addition you would most likely need an index for
>SampleDetail.MasterID (and possibly more indices depending on your
>WHERE-clauses).
an index yet, don't I?
I read somewhere that Interbase creates an index automatic for primary,
foreign and unique keys.
Regards,
Jörg
>I generally tend to use JOINs more often than subqueries, but that might beThese
>because I rarely do need 0 or 1 rows returned from a table (which you would
>require for a subselect).
>Set
>At 14:04 14.02.2001 +0100, you wrote:
>>Hi Jörg
>>
>>I have asked the same question half a year ago in the IBO-Mailinglist.
>>are the results in short words:you
>>1) When you just do a select without an order by, it doesn't matter, if
>>use a Join or a SubSelect.fields
>>2) When you select with an order by, you should use the subselect.
>>
>>
>>Guido.
>>
>>Jörg Schiemann wrote:
>>
>>> Hi,
>>>
>>> I've a master and a detail table like
>>>
>>> create table "SampleMaster" (
>>> MasterID integer not null primary key,
>>> OrderNo integer not null,
>>> Comment varchar(20),
>>> .
>>> .
>>> .
>>> );
>>>
>>> and
>>>
>>> create table "SampleDetail" (
>>> DetailID integer not null primary key,
>>> MasterID integer not null,
>>> OrderPos integer not null,
>>> quantity integer not null,
>>> .
>>> .
>>> .
>>> constraint fk_MasterID foreign key (MasterID) references SampleMaster
>>> (MasterID)
>>> );
>>>
>>> Is a query with a subquery faster then a joined query if I want all
>>> from the SampleDetail and only OrderNo from SampleMaster?To unsubscribe from this group, send an email to:
>>>
>>> TIA
>>>
>>> Jörg Schiemann
ib-support-unsubscribe@egroups.com