Subject | Re: SQL question |
---|---|
Author | Svein Erling |
Post date | 2003-10-21T07:17:47Z |
> Is this ok?Well, using IN <subselect> used to be very slow, though it may be
>
> SELECT MyRec, MyRec1 FROM MyRecTable WHERE MyDateField IN
> (SELECT OtherDate FROM OtherTable WHERE
> (OtherDate >= '1/1/2003 00:00:00')
> AND
> (OtherDate <= '12/31/2003 00:00:00'))
> ORDER BY
> MyDateField
>
> Or should I use a Join if possible?
improved in Firebird 1.5. Rewriting the above statement to
SELECT MyRec, MyRec1 FROM MyRecTable WHERE EXISTS (
(SELECT * FROM OtherTable WHERE
MyRecTable.MyDateField = OtherTable.OtherDate AND
OtherDate BETWEEN '1/1/2003 00:00:00' AND '12/31/2003 00:00:00')
ORDER BY
MyDateField
Using JOIN is generally a good idea, but not always possible.
HTH,
Set