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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:49:38+00:00 2026-06-01T08:49:38+00:00

I have a database with users and games. 1 game can have multiple users

  • 0

I have a database with users and games. 1 game can have multiple users so I made a linking table called users_games. The crux is that a game can always only have 2 players since it is a board game. I know which player I am, i have my user_id and my email, but I would like to gain a result that gives me a list of all games I am in WITH the user_id and email of the other fellow. So a query that looks to all games I am in and give the other row, with the name of the player.

My tables:

games

id (int)
board (varchar) representation of the board

users

id (int)
email (varchar)
password (varchar MD5)

users_games

id (int)
user_id (int)
game_id (int)

For clarification this query

SELECT * 
        FROM `tic_users_games` AS ug 
        LEFT JOIN tic_users AS u
        ON ug.user_id = u.id
        RIGHT JOIN tic_games AS g
        ON ug.game_id = g.id

And result

id  user_id     game_id     id  email   password    id  board   created     updated 

1   1   1   1   ME@gmail.com    d56b699830e77ba53855679cb1d252da    1   0|0|0|0|0|0|0|0|0   2012-04-02 16:56:06     2012-04-02 16:56:06
2   2   1   2   FOE1@gmail.com  d56b699830e77ba53855679cb1d252da    1   0|0|0|0|0|0|0|0|0   2012-04-02 16:56:06     2012-04-02 16:56:06
3   3   2   2   FOE2@gmail.com  d56b699830e77ba53855679cb1d252da    2   0|0|0|0|0|0|0|0|0   2012-04-02 16:56:06     2012-04-02 16:56:06
4   1   2   1   ME@gmail.com    d56b699830e77ba53855679cb1d252da    2   0|0|0|0|0|0|0|0|0   2012-04-02 16:56:06     2012-04-02 16:56:06

See: In the above case I just want 2 rows: game_id 1 and 2, with FOE1@… and FOE2@…

Thanks

  • 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-01T08:49:39+00:00Added an answer on June 1, 2026 at 8:49 am

    This should do it for you. The syntax might not be exact for mysql but you should get there. Basically get all users that have games in the user_games table with the same game_ID as the games I am in:

    SELECT
        User_Games.Game_ID,
        Users.ID,
        Users.Email
    FROM
        Users 
        LEFT JOIN User_Games ON Users.ID = User_Games.User_Id
    WHERE
        Users.User_ID <> @yourUserID
    AND EXISTS
        (SELECT
            NULL
        FROM
            User_Games AS MyUserGames
        WHERE
            User_Games.Game_ID = MyUserGames.Game_ID
        AND MyUserGames.User_ID = @yourUserID)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database of users where they can send messages to other users
I have a database with Users. Users have Items. These Items can change actively.
I have a large database of users (~200,000) that I'm transferring from a ASP.NET
So I'm creating a simple application. I have a 'Games' database table and a
Suppose I have a game that can be played by 2, 3 or 4
For a browser game, I have a database table fights : fightID fromID toID
I have a simple database that keeps track of transactions from multiple players in
I have a little game written in C#. It uses a database as back-end.
I have a database of users and a database of cards. The users see
I have a database which users should not be able to alter data in

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.