1

My problem is that in the result a user can be in it more then one time if he is in more then 1 higher ranked group.

SELECT xf_user_group_relation.user_id , xf_user_identity.account_name, xf_user_group_relation.user_group_id, MAX( xf_user_group.display_style_priority ) AS display_style_priority
FROM xf_user_group_relation
INNER JOIN xf_user_group ON xf_user_group_relation.user_group_id = xf_user_group.user_group_id
INNER JOIN xf_user_identity ON xf_user_group_relation.user_id = xf_user_identity.user_id
WHERE xf_user_group.display_style_priority >=1000 AND identity_service_id = 'Minecraft'
GROUP BY xf_user_group_relation.user_id, xf_user_group_relation.user_group_id, xf_user_identity.account_name

Result:

|user_id|account_name|user_group_id|display_style_priority|
|1|yuriman|5|10000
|1|yuriman|6|9000
|2|skull905|5|10000
|13|ryan1271|5|10000
|21|mr_matt|9|6000
|37|Gaurav251|12|1000
|38|tvmaniac9|9|6000
|38|tvmaniac9|11|2000
|44|robyrq|9|6000
|44|robyrq|12|1000
|86|sabasNL|11|2000
|86|sabasNL|15|5200
|128|Scarykittens|9|6000
|133|Sargent5|10|5000
|133|Sargent5|11|2000
|142|kevy76|9|6000
|142|kevy76|11|2000
|144|liljew29|10|5000
|144|liljew29|11|2000
|149|a7xtdgfan332|10|5000
|160|TheNeoStrike|11|2000
|189|CptToddney|11|2000

The result should look like this:

|user_id|account_name|user_group_id|display_style_priority|
|1|yuriman|5|10000
|2|skull905|5|10000
|13|ryan1271|5|10000
|21|mr_matt|9|6000
|37|Gaurav251|12|1000
|38|tvmaniac9|9|6000
|44|robyrq|9|6000
|86|sabasNL|11|2000
|128|Scarykittens|9|6000
|133|Sargent5|10|5000
|142|kevy76|9|6000
|144|liljew29|10|5000
|149|a7xtdgfan332|10|5000
|160|TheNeoStrike|11|2000
|189|CptToddney|11|2000

I want the result to have the users highest ranked group only which is the one with the highest display_style_priority. Im not sure how to fix that.

Best Regards

BlackVoid
  • 627
  • 1
  • 6
  • 21

1 Answers1

1

i think you need to change the group by

GROUP BY xf_user_group_relation.user_id, xf_user_identity.account_name
Haim Evgi
  • 123,187
  • 45
  • 217
  • 223