Forum Moderators: coopster

Message Too Old, No Replies

Avoid duplicates in MySQL result set

How to avoid having cola1 listed twice

         

dkin

6:27 pm on Aug 20, 2004 (gmt 0)

10+ Year Member



Ok, I am hoping someone has the solution to this. There is one of two things I can do. I have a database say for types of pop. So this is the db

Cola 1
Cola 2
Cola 3
Cola 1

all with unique id's.

I would like to display the names of cola on the main page but I would not like duplicates displayed regardless of how many there are.

So for the db i just displayed i would like the main page to look like this.

Cola 1
Cola 2
Cola 3

Now the beginners approach (mine) was create a seperate database and if the type of cola is not in that db enter it if it is dont do anything (can't figure this out either :-S)

Is there an easier way then what I am trying?

ergophobe

6:36 pm on Aug 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



First question, why are there duplicate rows? Is it because
- you're using shorthand and there are other fields which are unique? In which case thanks for simplifying it for us.
- you just have duplicate rows in your DB? In which case, the issue is with data entry rather than data extraction.

Assuming the first case, you just need this

SELECT DISTINCT(cola_name) FROM colas;

Voila! One row per cola_name

Tom

dkin

7:11 pm on Aug 20, 2004 (gmt 0)

10+ Year Member



you assumed right, thank you. made everything so much easier.