Arggh! The problem was not in the sql query/return, but in a difference between PHP 5.2.9 and 5.2.13 default handling of the array_unique function.

For PHP 5.2.9 (just my luck), the default sort order was SORT_REGULAR (which works for me); for all other versions, the sort order is SORT_STRINGS (which doesn't).