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
[SOLVED] Using DISTINCT function..
Moderator: General Moderators
Dont quite understand what you are trying to do, but I am guessing something like
you might want to explain it a little better, if thats not what you are trying to do.
Code: Select all
SELECT DISTINCT field1, field2 FROM mytable GROUP BY field1 ORDER BY field1-
fractalvibes
- Forum Contributor
- Posts: 335
- Joined: Thu Sep 26, 2002 6:14 pm
- Location: Waco, Texas
- andre_c
- Forum Contributor
- Posts: 412
- Joined: Sun Feb 29, 2004 6:49 pm
- Location: Salt Lake City, Utah
Maybe this is what you want?
Code: Select all
SELECT field1, field2 FROM mytable GROUP BY field1Code: Select all
SELECT DISTINCT field1, field2 FROM mytable GROUP BY field1 ORDER BY field1