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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:37:10+00:00 2026-05-19T04:37:10+00:00

Supposed that we have classes Person, Character, and PersonCharacter and their corresponding structure in

  • 0

Supposed that we have classes Person, Character, and PersonCharacter and their corresponding structure in following data structure and data in MySQL database.

table persons
[
  { id: 1, name: peter },
  { id: 2, name: mary },
  { id: 3, name: joe },
  { id: 4, name: paul },
  { id: 5, name: may },
]

table characters
[
  { id: 101, description: cheerful },
  { id: 102, description: nervous },
  { id: 103, description: greedy },
  { id: 104, description: sincere },
  { id: 105, description: naive },
  { id: 106, description: firm },
]

table person_characters
[
  {id: 1000, person_id: 1, character_id: 101},
  {id: 1001, person_id: 1, character_id: 103},
  {id: 1002, person_id: 1, character_id: 106},
  {id: 1003, person_id: 2, character_id: 102},
  {id: 1004, person_id: 2, character_id: 104},
  {id: 1005, person_id: 3, character_id: 102},
  {id: 1006, person_id: 3, character_id: 105},
  {id: 1007, person_id: 4, character_id: 104},
  {id: 1008, person_id: 5, character_id: 101},
  {id: 1009, person_id: 5, character_id: 106},
]

How can I write a SQL statement, if possible with help of Rails, that can find out that with persons who have particular characters? For example, persons with character both firm and cheerful are may and peter.

The question seems typical but it is hard to find the answer by search engines.

  • 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-19T04:37:11+00:00Added an answer on May 19, 2026 at 4:37 am
    SELECT  persons.*
    FROM    persons
      JOIN  person_characters
      ON    person_characters.person_id ON persons.id
        AND
          -- vvv Method one, we already have the character IDs: vvv
          person_characters.character_id IN (101,106)
          -- ^^^ /Method one ^^^
    
          -- vvv Method two, we need to look them up vvv
          person_characters.character_id IN (
            SELECT characters.id
            FROM   characters
            WHERE  characters.description IN ('cheerful','firm')
          )
          -- ^^^ /Method two ^^^
    

    NOTE use only one of those statements after the AND inside the join. I’m just showing either approach (if you do or do not have the ID(s) of the characters(s) to look for.

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

Sidebar

Related Questions

Suppose I have the following scala classes ( that needs to improve to address
I have these Javascript classes/code: function PageManager () { this.digital_channels = undefined; this.loadConfiguration =
I have two similar methods that take a criteria object (dumb object with a
Suppose I have two containers of elements: std::vector<std::string> foo = { aa, bb, cc
Suppose I need to inherit from two classes in C# . This is not
I've alway had trouble understanding the the documentation on how S3 methods are called,
I'm currently trying to access a URL with both HTTP and HTTPS. The URL
I've been stuck trying to puzzle this out for a couple days now, and
I'm having a tricky problem in the game I'm working on. I'm using Pygame
I'm new to serialization, so this might be a simple question, but my google-fu

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.