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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:59:24+00:00 2026-06-05T09:59:24+00:00

I asked a related question a week ago, but here’s another problem I’m facing.

  • 0

I asked a related question a week ago, but here’s another problem I’m facing. I feel like such a noob, but I guess it’s better to ask and learn than never learn.

Here are my three tables:

Fighters Table

fighter_id, name

Events Table

event_id, event_name, event_date

Fights Table

fight_id, fighter_a, fighter_b, winner, method, event

So in the fights table, fighter_a, fighter_b, and winner are integers that correspond to fighter_id in the Fighters table.

I’m basically on a page retrieving data based on fighter_id.

I’m trying to create rows with each fight of that fighter that includes his opponent’s name, result (win, loss, draw, or nc), method, event_name, and event_date. If it’s a Draw or No Contest, it’ll say Draw or No Contest in Method column, while winner will be NULL.

I was looking at these MySQL IF statements, and created what would be the appropriate criteria for determining whether a fighter won, lost, got a draw, or no contest. It doesn’t seem like these statements can be used in a PHP mysql_query, but at least it gives you an idea of criteria. I know I have to inner join these 3 tables together, but I’m not sure how to determine winner/loser/etc… because fighter_a or fighter_b can be a winner, or neither could be. I don’t know how to approach these IF statements in MySQL query.

IF winner IS NOT NULL AND winner=fighter_id THEN SET record='win';
ELSEIF winner IS NOT NULL AND winner<>fighter_id THEN SET record='loss';
ELSEIF winner IS NULL AND method='Draw' THEN SET record='draw';
ELSEIF winner IS NULL AND method='No Contest' THEN SET record='no contest';
ELSE SET record='';
ELSE IF;

I’m trying to get a result in a table that look something like this:
http://en.wikipedia.org/wiki/Fedor_Emelianenko#Mixed_martial_arts_record

  • 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-05T09:59:25+00:00Added an answer on June 5, 2026 at 9:59 am

    If I understand you correctly, I believe you would want to use a CASE statement to determine the result. The fighters will require a join, similar to this:

    select 
        fight_id,
        CASE
          WHEN winner is not null and winner=fighter_id then 'win'
          WHEN winner is not null and winner<>fighter_id then 'loss'
          WHEN winner is null and method='Draw' then 'draw'
          WHEN winner is null and method = 'No Contest' then 'no contest'
          ELSE ''
        END as match_result,
        participant.name 'participant',
        opponent.name 'opponent'
    FROM fights
        INNER JOIN fighters as participant on participant.fighter_id = fights.fighter_a
        INNER JOIN fighters as oppoent on opponent.fighter_id = fights.fighter_b
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is related to another question I asked last week, but the current issue
I've asked another related question to this here: casting dynamic to static problem I've
I asked another SOAP related question some time ago, which asks for a working
Related to a question I asked earlier here , I've found a problem which
This is another question related to a question I asked a few minutes ago.
I originally asked a related question here , but didn't really seem to get
This is related to a question I asked here: Thread Locking in Ruby (use
This question is related to another question I asked Basically, I have 2 horizontally
I've asked a related question here: Show unmatched html tags in Notepad++ Having only
I know I asked a related question earlier. I just had another thought. using

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.