MySQL distinct keyword - How do you retrieve each unique value?
I was looking at the distinct keyword in the SQL statement and I was wondering how you would get each individual columns. My guess was this:
PHP Code:
$sth = $dbh->query("SELECT distinct colName FROM table");
$i=0;
while($row=$sth->fetch()) {
$colVal.$i = $row[$i];
echo $colVal.$i;
$i++;
}
But I'm not sure that is quite right, or there may be a better way I'm just not seeing.
Last edited by as4s1n; 04-17-2010 at 04:19 PM.
There is no such thing as a "stupid question," there are only "stupid people" who don't ask them.