Click to See Complete Forum and Search --> : mysql and lists


daed17
10-24-2003, 10:10 AM
I have a list of duplicates (x,x,x,y,y,z) and I want to use php to have mysql to only retrieve one of each in the list (x,y,z).

Is there an easy way to do this? I have over 100,000 records so I am trying to stay away anything that looks like a bubble sort.

I am going brain dead over here today.

Khalid Ali
10-24-2003, 10:30 AM
if you have an array of records that may contain duplicates you can use a built in function in php e.g
$dupli = array (x,x,x,y,y,z);

$uniqArray = array_unique($dupli);

the variable $uniqArr contains only unique values.
If your concern is to retireve unique values from database then you can use

DISTINCT command

SELECT DISTINCT fieldName FROM tableName;

daed17
10-24-2003, 11:58 AM
the distinct worked great... that is exactly what was needing.

Thank you again.