Darius Darius - 19 days ago 5
SQL Question

select one row without duplicate entries

In mysql table

info
i have :


Id , Name , City , date , status


I want to select all names from "info"
Making the query

$query = mysql_query("SELECT name FROM info WHERE status = 1 ORDER BY id")
or die(mysql_error());

while ($raw = mysql_fetch_array($query))
{
$name = $raw["name"];
echo ''.$name.'<br>';
}


Well results is that it returns me all the entries.
I want to echo me all the entryes without duplicates

Saying: under raw "name" we have inserted the name "John" 10times ,

i want to echo only one time.
Is this posible?

Answer

It's pretty simple:

SELECT distinct name FROM info WHERE status = 1 ORDER BY id

The SQL keyword DISTINCT does the trick.