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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:50:19+00:00 2026-05-23T07:50:19+00:00

The database is quite simple. Below there is a part of a schema relevant

  • 0

The database is quite simple. Below there is a part of a schema relevant to this question

  • ROUND (round_id, round_number)

  • TEAM (team_id, team_name)

  • MATCH (match_id, match_date, round_id)

  • OUTCOME (team_id, match_id, score)

I have a problem with query to retrieve data for all matches played. The simple query below gives of course two rows for every match played.

select * 
from round r 
inner join match m on m.round_id = r.round_id 
inner join outcome o on o.match_id = m.match_id 
inner join team t on t.team_id = o.team_id

How should I write a query to have the match data in one row?

Or maybe should I redesign the database – drop the OUTCOME table and modify the MATCH table to look like this:

  • MATCH (match_id, match_date, team_away, team_home, score_away, score_home)?
  • 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-23T07:50:20+00:00Added an answer on May 23, 2026 at 7:50 am

    You can almost generate the suggested change from the original tables using a self join on outcome table:

    select o1.team_id team_id_1,
           o2.team_id team_id_2,
           o1.score score_1,
           o2.score score_2,
           o1.match_id match_id
    from outcome o1
    inner join outcome o2 on o1.match_id = o2.match_id and o1.team_id < o2.team_id
    

    Of course, the information for home and away are not possible to generate, so your suggested alternative approach might be better after all. Also, take note of the condition o1.team_id < o2.team_id, which gets rid of the redundant symmetric match data (actually it gets rid of the same outcome row being joined with itself as well, which can be seen as the more important aspect).

    In any case, using this select as part of your join, you can generate one row per match.

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

Sidebar

Related Questions

This question is quite simple but I have run into the problem a few
This question is quite simple but I'm not sure of the terms involved to
I am quite new to SQLAlchemy, or even database programming, maybe my question is
My question is I think quite simple but I don't think the answer will
Question Summary: Is there a better method than the one posted below to implement
This might be quite simple but I have spent hours in Google but couldn't
I'm using Mongoose to manage a Mongo database. My connection file is quite simple:
Hey guys, this should be quite simple to answer.... Im using XSB Prolog...trying to
I have a quite simple database query: Query q = new Query(person); q.addFilter(name, Query.FilterOperator.EQUAL,
I am working on a quite simple custom made content management system (CMS). There

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.