I am performing a query along the lines of the following:

SELECT DISTINCT property.Internal_ID
FROM property, owner_names
WHERE property.Internal_ID = owner_names.Internal_ID
AND [ other conditions ]
ORDER BY owner_names.Name

Without the order by clause this is a pretty quick query, but with it,
things
slow down considerably. The query then takes 5-10 times as long.     :(
the property table has 1,000,000+ records
and there are an average of about 1.4 owner_names records for each property
record

I'm not exactly sure what happens with the ORDER BY clause, because
if a property record has more than one owner_name record associated with
it, how does MySQL decide which to use for sorting?

I'd guess that if there are more than one, it will take the first one in
sort order.

The owner_names table also has a field named Display_Order, which determines
in what order to display the names for mailing labels, etc.
I'd really like the ORDER BY to only consider records with Display_Order =
1,
but the SELECT to consider all owner_name records.

I know you can put some types of expressions in an order by clause, but i
don't
know how to express the above concept in SQL.

thanks
sean peters
[EMAIL PROTECTED]



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to