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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:41:32+00:00 2026-06-06T17:41:32+00:00

I have 4 tables. Table A that has users – ( user_id, username, and

  • 0

I have 4 tables.

  1. Table A that has users – (user_id, username, and name)
  2. Table B that has tokens – (token_id, user_id). Each user has 10 token entries. Each token is assigned to only one user. A user has multiple tokens (10)
  3. Table C that is arcades games – (arcade_id, token_id, name, levels, lives). Only one token can be assigned to one arcade game only.
  4. Table D that is prizes – (prize_id, token_id, name, length, width, height). Only one token can be assigned to one prize only.

A token is assigned to either an arcade game or a prize or nothing but not both.

My question is how do set-up a MySQL join query to figure out which tokens for a given user are assigned to game or a prize or have not been assigned yet. Are my table layouts optimal? Or do you have suggestions for another layout?

Here are my tables:

mysql> select * from users;

+---------+--------+
| user_id | name   |
+---------+--------+
|       1 | User 1 |
|       2 | User 2 |
|       3 | User 3 |
|       4 | User 4 |
+---------+--------+

mysql> select * from tokens;

+----------+---------+
| token_id | user_id |
+----------+---------+
|        1 |       1 |
|        2 |       1 |
|        3 |       2 |
|        4 |       2 |
|        5 |       2 |
|       11 |       2 |
|        6 |       3 |
|        7 |       3 |
|       10 |       3 |
|        8 |       4 |
|        9 |       4 |
+----------+---------+

mysql> select * from prizes;

+----------+----------+-----------+
| prize_id | token_id | prizename |
+----------+----------+-----------+
|        1 |        4 | prize 1   |
|        2 |        7 | prize 2   |
|        3 |        8 | prize 3   |
|        4 |        9 | prize 4   |
+----------+----------+-----------+

mysql> select * from arcade;

+-----------+----------+----------+
| arcade_id | token_id | gamename |
+-----------+----------+----------+
|         1 |        1 | game 1   |
|         2 |        2 | game 2   |
|         3 |        3 | game 3   |
|         4 |        5 | game 4   |
|         5 |       11 | game 6   |
+-----------+----------+----------+

I would like a SQL query where I can get the following info:

For User 1, they have 2 tokens – token id 1 is assigned to game 1 and token id 2 is assigned to game 2

Or for user 2 – they have 4 tokens – token id 3 is assigned to game 3, token id 4 is assigned to prize 1, token id 5 is assigned to game 4.

Or for user 3 – they have 3 tokens – token id 6 is not assigned yet, token id 7 is prize 2, token id 10 is not assigned

and so on.

I would like to build a MySQL query string like this

Select **** 
  from ***** 
 Where user_id = 1

Where I specify the user id and get all the info above.

  • 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-06T17:41:35+00:00Added an answer on June 6, 2026 at 5:41 pm

    Try this query but if there was some data i would be able to check although i have checked with dummy data

    select
      t.token_id,
      IFNULL(g.game,'') as Game,
      IFNULL(p.name,'') as Prize,
      case when g.game != '' then 'Assigned' when p.name != '' then 'Assigned' else 'Not assigned yet' end as `Status`
    from token as t
      left join (select *
             from games
             where token_id not in(select
                         token_id
                       from prize)) as g
        on g.token_id = t.token_id
      left join (select *
             from prize
             where token_id not in(select
                         token_id
                       from games)) as p
        on p.token_id = t.token_id
    

    EDITED
    Then it should be the most simple thing to do

    select *
    from `user`
      left join token
        on user.user_id = token.user_id
      left join games
        on games.token_id = token.token_id
      left join prize
        on prize.token_id = token.token_id
    where user.user_id = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a user table 'users' that has fields like: id first_name last_name ...
Let's say I have a table that has user_id, date, score, and every user
I have three tables: Users Questions User_Questions 1.user questions has the columns user_id, question_id,
I have two tables. One is a 'Users' table. Each row (user) in the
I have a query that retrieves the name of each friend a user has
I have a table that has account numbers in (account_num) and user profiles (profile_id).
I have a User table that has all of their avatars saved in an
Currently I have a User table that has a toys_owned column that is an
I have a table that stores user information. The table has a userid (identity)
I have a table that includes 27 DropDownLists for user input. My table has

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.