Subject Re: query slow response
Author zifnabbe
> You have a view joining Persons and Zipcodes
> then you join that view back to a dependent of the Persons table
> and join again into the Zipcodes table...

mmm, this is my query:

SELECT blabla
FROM APPOINTMENTS A
LEFT OUTER JOIN VIEW_PERSONS P ON A.PERSON_ID=P.PERSON_ID

what do you mean with 'join again into the ZipCodes table?'

> I should think the optimizer gave up and went to the pub.
>
> Is there any reason why your view can't join all three tables, or
indeed why you can't just get this dataset with a plain SQL
statement, something like
>
> select p.personid, a.something, ... z.cityname, z.zipcode
> from appointments a
> join persons p on a.personid = p.personid
> join zipcodes z on p.zipcode=z.zipcode
> where <identified column> = ....

yes, I see, beautiful.
Now I've another problem (probably not that big for the gurus). In
the appointments table is another ID, named service_id (this is the
key to a service table, place where the person has to go). This
service table has also a zipcode_id.
How can I create a view which combines all this information:

The following query returns a result, but is this a correct query I'm
doing? I didn't new you could use several joins with the same table
(Postcodes)

select blabla
from appointments a
join persons p on a.personid = p.personid
join zipcodes z1 on p.zipcode=z1.zipcode
join services s on a.serviceid = s.serviceid
join zipcodes z2 on s.zipcode=z2.zipcode

do joins have a certain order in which they calculate?

I used left outer join in my own examples. eg :

select blabla
from appointments a
left outer join persons p on a.personid = p.personid
join zipcodes z1 on p.zipcode=z1.zipcode
left outer join services s on a.serviceid = s.serviceid
join zipcodes z2 on s.zipcode=z2.zipcode

Is this better?

Thanks,

Tom.