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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:32:01+00:00 2026-06-17T19:32:01+00:00

I have the following table setup in mysql: CREATE TABLE `games_characters` ( `game_id` int(11)

  • 0

I have the following table setup in mysql:

CREATE TABLE `games_characters` (
  `game_id` int(11) DEFAULT NULL,
  `player_id` int(11) DEFAULT NULL,
  `character_id` int(11) DEFAULT NULL,
  KEY `game_id_key` (`game_id`),
  KEY `character_id_key` (`character_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

My objective is to get a game_id where a list of character_ids are all present in this game_id.

An example set of data:

1, 1
1, 2
1, 3
2, 1
2, 2
3, 1
3, 4

Let’s say i want to get the game_id where the character_id has 1, 2, and 3. How would I go about making an efficient query? Best idea I have had so far was joining the table to itself multiple times, but i assume there has to be a better way to do this.

Thanks

EDIT: for anyone curious this was the final solution I used as it proved the best query time:

SELECT game_ID
FROM (
    SELECT DISTINCT character_ID, game_ID
    FROM games_Characters
) AS T
WHERE character_ID
IN ( 1, 2, 3 ) 
GROUP BY game_ID
HAVING COUNT( * ) =3
  • 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-17T19:32:02+00:00Added an answer on June 17, 2026 at 7:32 pm
    Select game_ID from games_Characters
    where character_ID in (1,2,3)
    group by game_ID
    having count(*) = 3
    
    the above makes two assumptions
    1) you know the characters your looking for
    2) game_ID and character_ID are unique
    

    I don’t assume you can get the #3 for the count I knnow you can since you know the list of people you’re looking for.

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

Sidebar

Related Questions

I have a MySQL table with following setup: CREATE TABLE IF NOT EXISTS `coords`
Assume the following in MySQL: CREATE TABLE users ( id integer auto_increment primary key,
I have the following setup: Table: Question QuestionId Table: QuestionTag QuestionId TagId Table: Tag
I have the following setup in MS IE8: <table class=my-info> <tbody> <tr> <td class=info-left>First
I have the following table drop table names; create table names( name varchar(200), surname
I have a MySQL table setup as follows: +---------------+-------------+------+-----+---------+----------------+ | Field | Type |
I have a simple MySQL table that is setup for full text search. |
I am looking for some, I have the following table setup in my test
setup: mysql> create table product_stock( product_id integer, qty integer, branch_id integer); Query OK, 0
setup: mysql> create table product_stock( product_id integer, qty integer); Query OK, 0 rows affected

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.