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

  • Home
  • SEARCH
  • 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 8331629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:28:15+00:00 2026-06-09T02:28:15+00:00

I have a table, matches , which contains sports fixture data with fields including

  • 0

I have a table, matches, which contains sports fixture data with fields including home_pom (home player of the match) and away_pom. I need to call a query to find the top 5 values across those two fields (i.e. the 5 people with the most player of the match awards overall from season x), with the capacity to output the number of occurrences and the name of the player.

I have no real clue where to start with the SELECT function.

The matches table contains a league_id field which corresponds to a separate leagues table, called to $league_id earlier in the page. There’s currently no separate players table – I thought it would probably be redundant since this is pretty much the only thing I can consider it being relevant for.

i.e.

match_id | homepom | awaypom | league_id  
1        | Joe A   | Jane B  |  2  
2        | Joe F   | Jane G  |  2  
3        | Jane B  | Joe F   |  2  

to list Joe F and Jane B as having 2 pom awards, and Jane G and Joe A as having one.

$host="cust-mysql-123-05"; // Host name 
$username="unsn_637140_0003"; // Mysql username 
$password="mypw"; // Mysql password 
$db_name="nsnetballcouk_637140_db3"; // Database name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$areatoleaguepom=$_GET['area'];
$seasontoleaguepom=$_GET['season'];
$divisiontoleaguepom=$_GET['division'];
$leaguepom_query=("SELECT league_id FROM leagues WHERE area_id='$areatoleaguepom' AND      season_id='$seasontoleaguepom' AND division_id='$divisiontoleaguepom'");
$leaguepom_result=mysql_query($leaguepom_query);
$leaguepom_row=mysql_fetch_array($leaguepom_result);
$leaguepom_id=$leaguepom_row['league_id'];

$toppom_query=(
"SELECT
player,
COUNT(player) as count
FROM (SELECT homepom AS player
FROM matches
WHERE league_id='$leaguepom_id'
UNION ALL
SELECT awaypom AS player
FROM matches
WHERE league_id='$leaguepom_id'
) as players
GROUP BY player
ORDER BY count DESC 
LIMIT 5
");

$toppom_result=mysql_query($toppom_query);
while ($toppom_row=mysql_fetch_array($toppom_result));

echo $toppom_row['player'] . " " . $toppom_row['count'] . "<br>";

any thoughts?

  • 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-09T02:28:18+00:00Added an answer on June 9, 2026 at 2:28 am

    This might be a bit overcomplicated, but anyway…

    SELECT
        player,
        COUNT(player) as count
    FROM (
        SELECT homepom AS player
        FROM matches
        WHERE homepom IS NOT NULL AND homepom != '' AND league_id = xxx AND other_things
        UNION ALL
        SELECT awaypom AS player
        FROM matches
        WHERE awaypom IS NOT NULL AND awaypom != '' AND league_id = xxx AND other_things
    ) as players
    GROUP BY player
    ORDER BY count DESC 
    LIMIT 5
    

    You merge the home_pom and away_pom in one column, then do a group by to count who has the most.

    Edit: removed the player table…

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

Sidebar

Related Questions

I have a classified_id variable which matches one document in a MySql table. I
I have 2 tables: matches TABLE FIELDS: record, date, competition outrights TABLE FIELDS: record,
I have a table which displays some names and each row contains 3 cells.
I have table Users which contains columns Login and Phone and I have table
I have mysql table 'files'. which contains following order. 1. id 2.filename 3.keywords When
I have the following problem: In mysql I have a table which contains two
I have table called FinalForgotten which only contains one field called aname. The field
A field in mysql table server_var_dump which contains many details including USER_AGENT of the
I have a database table which holds meta data about images, the field in
I have a situation where i have Keyword column in table which contains comma

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.