如何select人依赖一对多关系

How to select person depending on one to many relationship

我有table个人

create table Person  (
  id SERIAL not null,
  ...
);

一个人可以有 0 个或多个 PreviousName

create table PreviousName  (
  id       SERIAL    not null,
  person_id INTEGER  not null,
  value     VARCHAR(120)   
);

我怎样才能 select 所有在以前的名字中具有例如价值的人 "John"

select * from Person
where id in (select person_id from PREDCHOZI_JM_PR 
             where value = 'John')

我是这样理解你的问题的……

  SELECT * FROM Person LEFT JOIN PREDCHOZI_JM_PR ON person.id=PREDCHOZI_JM_PR.person_id 
  WHERE value="John"

您可以从 PREDCHOZI_JM_PR 中找到不同的 person_id,其值包含 john:

SELECT * FROM Person WHERE id IN (SELECT DISTINCT person_id FROM PREDCHOZI_JM_PR WHERE value LIKE '%John%')