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 7035461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:18:25+00:00 2026-05-28T01:18:25+00:00

I am having trouble coming up with a workable table design for tracking head-to-head

  • 0

I am having trouble coming up with a workable table design for tracking head-to-head match results between users.

All users have a UID. Individual match results are stored in another table, and each match has its own UID.

What I want is to be able to pull something like this with a simple select:

Player   vs.    Opponent   Wins   Losses   Draws
Bob             John       5      2        1
Bob             Sam        0      3        2
John            Bob        2      5        1

I can pull this data out of the raw match results with some manipulation in PHP, but it’s rather costly so I’d like to use cron jobs and store these “finished” statistics in a table for quick reads.

What’s tripping me up is the fact that one data set (2 players, win, loss, draw counts) can be read in two directions, depending on which player’s point of view you want, as depicted above for Bob and John.

I could make a table like this:

[player]  [opponent]  [wins]  [losses]  [draws]

but then each “set” would require two rows…

[player]  [opponent]  [wins]  [losses]  [draws]
bob       john        5       2         1
john      bob         2       5         1

and that duplication seems like it might cause me problems later, though off the top of my head I can’t think of a reason why, just DRY and all that…

Suggestions?

  • 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-05-28T01:18:26+00:00Added an answer on May 28, 2026 at 1:18 am

    I’ve seen the duplication approach you mention used effectively. So long as you’re aware of the duplication, it’s not too difficult to handle.

    If you want to avoid the duplication, you’ll probably need more code, and more code complexity: to show all the results for a single player, you’d need to find the records where that player is either “Player” or “Opponent”.

    One (I’d argue) useful way to report all the players’ records (versus their opponents) would be to display each “versus” records twice — once as a Player, grouped together, and once as an Opponent, in each of the sets of records for their opponents:

    Player   vs.    Opponent   Wins   Losses   Draws
    Bob             John       5      2        1
    Bob             Sam        0      3        2
    John            Bob        2      5        1
    John            Sam        1      2        1
    Sam             Bob        3      0        2
    Sam             John       2      1        1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble coming up with this solution logically. I have an accounts table
I'm having trouble coming up with a query that will find all customers who
I am having trouble coming up with a jQuery script that will all content
I'm having trouble coming up with a regular expression to match a particular case.
I'm having trouble coming up with a working query for this situation... Table: [
i am having a bit of trouble with DataInputStreams, So i have data coming
I'm having trouble coming up with an RegExKitLite expression that will match. I'm parsing
I have more of a .NET background, so I've been having some trouble coming
I'm having trouble coming up with the correct regex string to remove a sequence
I'm having trouble coming up with the proper syntax for allowing either a string

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.