MySQL DISTINCT to Remove Duplicate Listing

How to select and display records from MySQL table using the DISTINCT keyword for unique data.

This is for removing duplicated results in order to gain unique listings from
your database table using the DISTINCT keyword in your
MySQL select statement .

For example if you ran this:

Select Cars FROM Cars_Listing
======== Results =======
BMW
BMW
HONDA
BENZ
BENZ
BMW
FORD
FORD
=======================

Notice how there is more then one BMW.

Here is how to clean up that result by using the DISTINCT keyword in your
MySQL select statement

Select DISTINCT Cars FROM Cars_Listing
======== Results =======
BMW
HONDA
BENZ
FORD
=======================

7 Responses

  1. hahaha… I did stupid thing before I read this article. Thank you so much, I did not realize this damn good function.

  2. MC

    It really annoys me when people use ‘then’ instead of ‘than’. For example, ‘Notice how there is more THAN one BMW.’.

  3. I need it, thx. Good bye.

  4. ray

    I need a combined query that filters on multiple fields and then removes duplicates for one field

    for instance

    id name sports
    1 john soccer
    2 john tennis
    3 jane tennis

    mysql_query(“SELECT * FROM table WHERE `sports` = ‘soccer’ “);
    mysql_query(“SELECT * FROM table WHERE `sports` = ‘tennis’ “);

    now I found john twice, but I need him only once

    any suggestions?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Next Post » »