Page 1 of 1

[SOLVED] Using DISTINCT function..

Posted: Mon Mar 01, 2004 6:38 am
by raymedia
Hi guys..hows going. Just need some help in mysql syntax.

I need to select two fields (field1 and field2) in table "mytable" and A have to be distinct.

So i wrote,

SELECT DISTINCT field1, field2 FROM mytable ORDER BY field1

and all it does is selecting all field1, field2 including duplicates. I did some reseach online but no luck. Can any SQL gurus help me..Please...Thank you

Posted: Mon Mar 01, 2004 7:12 am
by Wayne
Dont quite understand what you are trying to do, but I am guessing something like

Code: Select all

SELECT DISTINCT field1, field2 FROM mytable GROUP BY field1 ORDER BY field1
you might want to explain it a little better, if thats not what you are trying to do.

Posted: Mon Mar 01, 2004 10:01 am
by fractalvibes
The sql you have will return every distinct combnation of field1 and field2.
so if your data looks like:

f1 f2
a b
a b
c r
e f
a c
e f

you will get a b, c r, e f, and a c returned.

fv

Posted: Mon Mar 01, 2004 10:54 am
by andre_c
Maybe this is what you want?

Code: Select all

SELECT field1, field2 FROM mytable GROUP BY field1

Posted: Tue Mar 02, 2004 5:29 am
by raymedia

Code: Select all

SELECT DISTINCT field1, field2 FROM mytable GROUP BY field1 ORDER BY field1
solved my problem..thank you all for your help