$query = "SELECT meta_value AS gender, user_id "
. "FROM $wpdb->usermeta "
. "WHERE user_id IN (" . implode( ',', $ids ) . ") AND meta_key='gender'";
$query = "SELECT min(user_id), gender, age "
. "FROM $wpdb->usermeta "
. "GROUP BY gender, age WHERE user_id IN (" . implode( ',', $ids ) . ")";