<?php $do_not_duplicate[] = 0; $i = 0; ?>
<?php $query = new WP_Query( 'posts_per_page=-1' ); ?>
<?php if ( have_posts() ) : while ( have_posts() && $i<6 ) : $query->the_post();
$category = get_the_category();
if (!in_array($category[0]->cat_ID, $do_not_duplicate)) :
$do_not_duplicate[] = $category[0]->cat_ID;
$i++;
?>
<!--[HTML for show posts]-->
<?php endif; ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>