访问 table 中链接到另一个 table 的所有行

Access all rows in table that is linked to another table

我在 SQLite 中有 2 个表。一个叫contacts,另一个叫phoneNumbersphoneNumbers 通过 integer references 链接到 contacts。这是表格:

CREATE TABLE contacts(
    id INTEGER PRIMARY KEY,
    name text
);

CREATE TABLE phoneNumbers(
    id INTEGER PRIMARY KEY,
    homePhone text,
    contact_id INTEGER REFERENCES contacts(id)
);

我的问题是,如何访问链接到 contacts (id) 1 的所有 homePhone

希望这是清楚的。如有任何问题,欢迎在评论中提问。

给你:

SELECT homePhone 
FROM phoneNumbers 
JOIN contacts
ON homePhone.contact_id=contacts.id
WHERE contacts.id=1 

永远不要使用 SELECT * :