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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:07:50+00:00 2026-06-18T09:07:50+00:00

I have this two tables. I have current player id_player, I want to select

  • 0

I have this two tables. I have current player id_player, I want to select all games from this player (id_player) and his opponents info. Current player and opponent player are connected with same id_game. or

tables

table game:`id_game` (...)
table game_player:`id_game_player, id_player, id_game`(...)

“give me all separate game info from current player and his opponent
and join info for their game (grouped by game)”

result as:

      +---player game info
game1 |
      +---opponent game info

      +---player game info
game2 |
      +---opponent1 game info

      +---player game info
game2 |
      +---opponent2 game info

Can anyone provide me MySQL solution?

Thanks


EDIT:
I try with this code but I’m not sure this is fastest way (WHERE IN) and is there any way to group results like above?

SELECT * FROM game_player
    JOIN `game` ON game.id_game = game_player.id_game
    WHERE game_player.id_game
    IN (
    SELECT game_player.id_game
    FROM `game_player`
    WHERE game_player.id_player =2)
  • 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-18T09:07:52+00:00Added an answer on June 18, 2026 at 9:07 am

    give this a try

    SET @player_ID = 0;                  -- <<== the playerID
    SELECT  a.*, b.*, 'player' Status         -- this is the first part of the union
    FROM    game a                            -- which gets all the game of
            INNER JOIN game_player b          -- the selected player and its info
                ON a.id_game = b.id_game
    WHERE   id_player = @player_ID 
    UNION ALL
    SELECT  d.*, c.*, 'opponent' status
    FROM    game_player c
            INNER JOIN
            (
                SELECT  a.*
                FROM    game aa
                        INNER JOIN game_player bb
                            ON aa.id_game = bb.id_game
                WHERE   bb.id_player = @player_ID
            ) d ON c.id_game = d.id_game AND c.id_player <> @player_ID
    ORDER   BY id_game, status
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this two tables from my program to manage stock: Articulos (items): id_articulo
I have two mysql tables and i want to do a select query: My
I have two tables. I want to mirror the values from one table to
I have this two tables: Table A ID TYPE SDATE EDATE RATING 1 M
I have two tables: This is table1: product_id|product_desc|product_name|product_s_desc This is table2: product_price_id|product_id|product_price Now I
I have two tables which looks something like this Table Queue int ID; string
I have two tables like of this structure: content (content_id, content_type, user_id, time, comment_count)
I have two tables associated by FK. Table student is mapped like this: @Entity
I have two tables Department and Employee . Department table looks like this: ID
Let's say I have two tables that look like this: TH TH TH TH

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.