Page 1 of 1

mysql_fetch_array question

Posted: Fri Feb 10, 2006 3:30 pm
by jrucifer
this is a rather simple question, so i hope there is a simple answer...

is there any way to have mysql_fetch_array output only 1 of many similar entries in the database?

for example, if these were entries in my database:

a
b
a
b
b
c
c
c

the output would be:

a
b
c

Thanks for any help.

Posted: Fri Feb 10, 2006 3:34 pm
by LiveFree
The sql would be ...

"SELECT DISTINCT * FROM table"

Posted: Fri Feb 10, 2006 3:41 pm
by jrucifer
great, even more simple than i was hoping for. Thanks a lot.

Posted: Fri Feb 10, 2006 9:53 pm
by Ambush Commander
I wonder why he would need this though... it's generally good practice to assign a non-meaningful id to all entries in databases.

Posted: Sat Feb 11, 2006 6:06 am
by Benjamin
Doesn't it have to be similar to this?

Code: Select all

select distinct `distinctfield`, `otherfield`, `anotherfield` from `thetable` group by `distinctfield`

Posted: Sat Feb 11, 2006 9:29 am
by feyd
using group by or distinct will generally do the job, however using both can be overkill.