Solved Compare and Output values of the same field in a table

AlexN

Registered User.
Local time
Today, 23:37
Joined
Nov 10, 2014
Messages
302
Hi everyone again,

I have a table with some data, the kind showing in the following image:
tblGroups.JPG


I want to query (or whatever else needed) this table and get the groups having same number of members the way shown below:


Group DGroup E
8​
Group DGroup F
8​
Group EGroup F
8​
Group GGroup H
7​
Group JGroup K
4​
Group JGroup L
4​
Group KGroup L
4​

I also want this to be able to change dynamically as data in table does. Is it doable?

Thank you all in advance
 
Can do a self-join linking on MembersCount field. Problem is records will be double because you'll get pairs going both ways, like:

D F
F D

Another option is to use Allen Browne's ConcatRelated function http://allenbrowne.com/func-concat.html to produce an output like:


MembersCountExpr1
2​
n
3​
m
4​
j, k, l
6​
i
7​
g, h
8​
d, e, f
9​
c
10​
b
15​
a
 
Can do a self-join linking on MembersCount field. Problem is records will be double because you'll get pairs going both ways, like:

D F
F D

Another option is to use Allen Browne's ConcatRelated function http://allenbrowne.com/func-concat.html to produce an output like:


MembersCountExpr1
2​
n
3​
m
4​
j, k, l
6​
i
7​
g, h
8​
d, e, f
9​
c
10​
b
15​
a
Thanks,
1st suggestion looks good but, seems I can't manage to get the results the way I want. Tried linking MembersCount field but I'm getting all records twice. I only want all possible variations of the equal ones
 
from the look of the desired output a self join should be sufficient combined with a criteria

Code:
SELECT A.groupname, B.groupname, B.memberscount
FROM tblGroups A INNER JOIN tblGroups B ON A.memberscount=B.memberscount
WHERE B.groupname>A.groupname
ORDER BY A.groupname
 
from the look of the desired output a self join should be sufficient combined with a criteria

Code:
SELECT A.groupname, B.groupname, B.memberscount
FROM tblGroups A INNER JOIN tblGroups B ON A.memberscount=B.memberscount
WHERE B.groupname>A.groupname
ORDER BY A.groupname
That seems to do the job. So easy but couldn't find it.
Thank you so much CJ.

Thank you all, you've been so helpful all these years.
 
Dang, I was close. Difference was I used <> instead of >.
 

Users who are viewing this thread

Back
Top Bottom