Web Hosting Talk







View Full Version : PHP/MySQL and Distinct


jon31
05-09-2005, 08:28 PM
Hey guys,

I've got a mysql table that may have duplicate field entries for the field "name". I'd like to list all these entries, but not list any duplicates.

Now I can do that with distinct, if I use:

SELECT DISTINCT(name) FROM table

But then I can't access any of the other information in the table. Can someone tell me how to use distinct in conjunction with using * to select all the fields for listing?

I hope that made sense.

Jon Marus

jon31
05-09-2005, 08:43 PM
I've found that I can do DISTINCT(name), age, location

But is there a way to do DISTINCT(name), * ?

t3r0
05-09-2005, 08:45 PM
try something like:


SELECT DISTINCT(t.name), t.* FROM table t;

jon31
05-09-2005, 08:50 PM
Ah, so simple. Thank you t3r0.