Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7890965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:29:40+00:00 2026-06-03T06:29:40+00:00

Im trying to make it select the group with the highest display priority. The

  • 0

Im trying to make it select the group with the highest display priority.
The problem is that it selects the group with the lowest ID and I’m not sure how to select the group with the highest display priority.

The SQL query looks like this:

SELECT xf_user_group_relation.user_id , 
       xf_user_field_value.field_value,
       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_field_value ON xf_user_group_relation.user_id = xf_user_field_value.user_id
WHERE xf_user_group.display_style_priority >= 500 
      AND field_id = 'minecraft' 
      AND xf_user_group_relation.user_group_id NOT IN(21,22)
GROUP BY xf_user_group_relation.user_id, 
      xf_user_field_value.field_value;

The groups are in xf_user_group with the structure:

user_group_id            int(10)        AUTO_INCREMENT
title                    varchar(50)
display_style_priority   int(10)
user_css                 text
user_title               varchar(100)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T06:29:41+00:00Added an answer on June 3, 2026 at 6:29 am

    MySql errorneously lets you aggregate values without specifing ALL non-aggregates in GROUP BY. So it chooses on its own what value to show for user_group_id.
    To get results you need, one would have to get maximum display_style_priority per user, and then join user_id and value back to original tables to filter them. There are two forms you might use, join:

    SELECT *
    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_field_value 
            ON xf_user_group_relation.user_id = xf_user_field_value.user_id
         INNER JOIN
         (
           SELECT r2.user_id, MAX(g2.display_style_priority) display_style_priority
             FROM xf_user_group_relation r2
            INNER JOIN xf_user_group g2 
               ON r2.user_group_id = g2.user_group_id
            GROUP BY r2.user_id
         ) maxDSP
            ON xf_user_group_relation.user_id = maxDSP.user_id
           AND xf_user_group.display_style_priority = maxDSP.display_style_priority
    WHERE xf_user_group.display_style_priority >= 500 
          AND field_id = 'minecraft' 
          AND xf_user_group_relation.user_group_id NOT IN(21,22)
    

    And compare to maximum in a subqery:

    SELECT *
    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_field_value 
            ON xf_user_group_relation.user_id = xf_user_field_value.user_id
    WHERE xf_user_group.display_style_priority =
          (SELECT MAX(g2.display_style_priority) 
             FROM xf_user_group_relation r2
            INNER JOIN xf_user_group g2 
               ON r2.user_group_id = g2.user_group_id
            WHERE r2.user_id = xf_user_group_relation.user_id
          )
          AND xf_user_group.display_style_priority >= 500 
          AND field_id = 'minecraft' 
          AND xf_user_group_relation.user_group_id NOT IN(21,22)
    

    Live demo is at Sql Fiddle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to make a make generic select control that I can dynamically add elements
I'm trying to make a select that calculates affiliate payouts. my approach is pretty
I'm trying to make the following query work: SELECT DATE_FORMAT( date, '%Y %m' )
I'm trying to make a query that would do something like this... id |
I have an SQL query: SELECT ShipVia, SUM(Freight) FROM Orders GROUP BY ShipVia which
So, the query I'm trying to make looks like this right now: SELECT `jid`,
Im trying to make a a query, but its doubling the Sum values SELECT
hi i am trying to make a query that will run records from a
I'm trying to make a select statement that joins results from three in-line table
I'm trying to make a SQL statement that gives me the top X records

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.