우리는 Person, Character, PersonCharacter 클래스와 그 구조를 다음과 같은 데이터 구조와 MySQL 데이터베이스의 데이터로 가정했습니다. 레일의 도움으로 가능하면두 테이블에 대한 SQL AND 조건
는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},
]
는 나는 SQL 문을 쓸 수있는 방법
는, 그 특정 문자가 사람과 것을 찾을 수 있습니까? 예를 들어, 확고하고 쾌활한 성격을 지닌 사람은 피터 (피터) 일 수 있습니다.
질문은 일반적인 것처럼 보이지만 검색 엔진에서 대답을 찾기가 어렵습니다.
"성"id 또는 wou를 이미 알고 있습니까? 그걸보아야 해? [이것은 본질적으로 JOIN 질의이지만 아직 가지고 있지 않다면 더 깊이있는 문자 id를 참조해야합니다.] –
나는 이것을 살펴볼 필요가 있습니다. – OmniBus
'PersonCharacter'는 매우 의미있는 데이터 요소 이름 인 IMO가 아닙니다. '성격'은 어떻습니까? – onedaywhen