Darius Darius - 1 year ago 90
SQL Question

select one row without duplicate entries

In mysql table

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 Source

It's pretty simple:

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

The SQL keyword DISTINCT does the trick.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download