Jump to content

[SOLVED] Looping through multiple results only once each...


ShootingBlanks

Recommended Posts

Hello.

 

I have a result set from a MySQL query that has some duplicates, but I want to list each instance only once...

 

...So, let's say I had a database column called "letters" that had the letters A-J in it.  Then let's say that my result set from my query was:

 

A, A, B, C, F, F, F, F, G, I, I, J

 

(the reason for the duplicates are because of a join query with another table)

 

I would want to "echo" each letter in my result set only once.  So, I'd like to list out:

 

A, B, C, F, G, I, J

 

How would that be possible?  Thanks!!!

 

 

Use DISTINCT

 

SELECT DISTINCT(letters) FROM ...

 

But I still need all the rest of the result set.  So, for instance (to elaborate on my original example) instead of simply saying that my result set was:

 

A, A, B, C, F, F, F, F, G, I, I, J

 

...let's say that it's actually:

 

COL1  COL2
A    1
A    2
B    3
C    7
F    3
F    4
F    2
F    5
G    1
I    6
I    1
J    3

 

If I used "DISTINCT", then wouldn't I only get one of each letter's entry?  (so, like, I may get the "A, 1" result but not the "A, 2" result, right?)...

 

Using the 2-column result I just wrote above, my ultimate goal is something like this (which should give you more insight as to why I asked my original question):

 

A    1
     2

B    3

C    7

F    3
     4
     2
     5

G    1

I    6
     1

J    3

 

Thanks!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.