Alter SQL query to return posts with unique custom field value, no duplicate values

If you have several posts with the same value, but you want only the most recent ones with any value, as long as values don’t get repeated, you’r best bet might be running two loops on the same query:

/* Fetch all possible values - use this to order the 
results and define which get selected */
$valueids = new WP_Query(array(
posts_per_page => -1,
meta_key => 'key',
));

/* First loop, to build an array of ids with single values */
$values = array();
$ids = array();
while ($valueids->have_posts()) : $valueids->the_post();
    $val = get_post_custom_values('key');
        if(!in_array($val,$values) {
            $values[] = $val;
            $ids[] = $post-ID;
        }
endwhile;

$valueids->rewind_posts();
$valueids->set( 'posts_per_page', 10 ) /* loop only for the ones you want */

/* Second loop, leaving out duplicated entries */
while ($valueids->have_posts()) : $valueids->the_post();
    if(in_array($post->ID,$ids) {
            // do you thing here
        }
endwhile;

ps: this is untested, but it should work properly.